Ask coding questions

← Back to all posts
How to make a vector that runs functions?
Typhlotion

Title says it all. I'm new to C++ and wanted to make a vector of functions to make my text based game work better. Would there be any way to make that work (or make a system where you can swap out several functions for one another)? Right now my code just gives me a wall of errors because I was stupid enough to make a vector of voids, but I think it's a pretty good example of what I'm trying to get working.
Thanks in advance, sorry if my code is atrocious.

Answered by ANDREWVOSS [earned 5 cycles]
View Answer
Voters
Typhlotion
Comments
hotnewtop
ANDREWVOSS
Typhlotion

@ANDREWVOSS I tried this solution and named the vector "functions" and although it didn't give out a wall of errors, it still doesn't actually run the functions. What do I have to do to make it work?

ANDREWVOSS

@Typhlotion I was a bit wrong. it should look like

Typhlotion

@ANDREWVOSS That definitely did it. Thanks

ANDREWVOSS

@Typhlotion no problem :D