i'm trying do 1 thing, but i'm 'stuck' :(
i try the functions pointers too, but without sucess :(
i understand the objects are the way for work with class's. until here fine.
but why i can't change the virtual functions from an object? is there anyway for do it?
i can't do, outside of class\functions, these code:
#include <iostream>
usingnamespace std;
class test
{
public:
virtualvoid created(){};
void run() { created(); }
};
class test2 : public test
{
public:
virtualvoid created();
};
void test2::created()
{
cout << "hello world";
}
int main()
{
test2 a;
a.run();
cin.get();
}
Notice, I took the virtual function call out of the constructor. It is undefined behavior (I believe) to call a virtual function from within a constructor. I'm sure one of the other forum denizens will quote the appropriate paragraph from the standard (or prove me wrong).
The tutorial on this site is excellent. It is worth the effort to go through. To learn more about virtual functions and polymorphism, see the following chapter: http://www.cplusplus.com/doc/tutorial/polymorphism/