So, clearly I’m doing something wrong…
#include <iostream>
using namespace std;
class thing1
{
public:
void thingTest()
{
cout << "I AM THING 1\n";
}
};
class thing2: public thing1
{
public:
void thingTest()
{
cout << "I AM THING 2\n";
}
};
void DoStuff( thing1 temp )
{
temp.thingTest();
}
void main()
{
DoStuff( thing2() );
}
I expect this code to output:
I AM THING 2
but instead I get:
I AM THING 1
the “final” goal of this project is to create a LinkedList of classes that store tasks in the form of void WorkClass.Do( void ). Each inharted class would be a different task (most of them have to do with rendering interface with my graphics engine). I want to EnQueue the constructor, then when DoWork() is called, DeQueue WorkClass.Do() until I hit a null pointer.
I figured being able to do this simple thing would be a good start to making all that other stuff work… but as it is, I’ve hit a brick wall. I assume I’ll have to do something with pointers…
You are taking them by value, which is slicing them. You must use reference or pointer (reference to const, or rvalue reference, in this case as they are rvalues)
Note the use of the
virtualkeyword. It is only needed on the method declaration in the base class- inherited members which arevirtualarevirtualby default.A fixed version on ideone.