J
Jonas Huckestein
Hello,
I have the following problem: I have one BaseClass, which defines the
virtual functions getValue(int index) and virtually overloads the operators
*, /, -, +. Now I want two classes SubClass1 and SubClass2 which extend the
BaseClass and implement the virtual functions, so that I can go like this:
BaseClass *oskar = new SubClass1;
BaseClass *newton = new SubClass2;
BaseClass *pete = oskar*newton+newton/oskar;
Is there a way I can accomplish this? Somehow I can't even get the easiest
situation straight, in which I have only two classes and 1 virtual
function:
class BaseClass {
public:
virtual int getValue( int index );
};
class SubClass1 : public BaseClass {
int getValue( int index ) { return 1; };
};
....
int main() {
BaseClass* oskar = new SubClass1;
cout << oskar->getValue(4); // supposed to be 1
delete oskar;
}
Now the compiler tells me: "undefined reference to `vtable for BaseClass'"
and "undefined reference to `typeinfo for BaseClass'"
I use g++-4.1. as a compiler, although I suppose the problem is due to my
lack of understandding C++ ...
Thanks in advance and greetings from Germany,
Jonas
I have the following problem: I have one BaseClass, which defines the
virtual functions getValue(int index) and virtually overloads the operators
*, /, -, +. Now I want two classes SubClass1 and SubClass2 which extend the
BaseClass and implement the virtual functions, so that I can go like this:
BaseClass *oskar = new SubClass1;
BaseClass *newton = new SubClass2;
BaseClass *pete = oskar*newton+newton/oskar;
Is there a way I can accomplish this? Somehow I can't even get the easiest
situation straight, in which I have only two classes and 1 virtual
function:
class BaseClass {
public:
virtual int getValue( int index );
};
class SubClass1 : public BaseClass {
int getValue( int index ) { return 1; };
};
....
int main() {
BaseClass* oskar = new SubClass1;
cout << oskar->getValue(4); // supposed to be 1
delete oskar;
}
Now the compiler tells me: "undefined reference to `vtable for BaseClass'"
and "undefined reference to `typeinfo for BaseClass'"
I use g++-4.1. as a compiler, although I suppose the problem is due to my
lack of understandding C++ ...
Thanks in advance and greetings from Germany,
Jonas