Im confused what virtual int and virtual string means.
Moreover, I'm confused what the prefix "virtual" has to do with anything; I have a feeling it has to do with vectors.
Im confused what virtual int and virtual string means.
Moreover, I'm confused what the prefix "virtual" has to do with anything; I have a feeling it has to do with vectors.
The virtual
has nothing to do with the int
, nor does it have anything to do with vectors. The int
specifies the type of value the function returns when it's done. The virtual
specifies that the function call be handled in a special way that's related to inheritance.
I expect this question has duplicate answers on here already. Search for stuff about the virtual
keyword in C++.
Your question is a very elementary C++ question, and I believe a full explanation of what virtual
means is outside the scope of what StackOverflow can help you with anyway. You should find a nice beginners C++ book.
virtual
describes a class member function in most cases.
If you see virtual int some_function()
it's the function that's virtual.
You can learn about the concept here.
In C++ "virtual" is a keyword used in a class' or struct's method declarations that makes the function polymorphic based on the object type. You can read up on the basic, language-independent concept at http://en.wikipedia.org/wiki/Virtual_function, but you'd be best served reading an introduction C++ book to learn how this is used.