"Tobias Blomkvist" <vo**@void.void> wrote in message
news:1124706132.2c6fd907fae848b84404faf38ad59909@t eranews...
Tony Johansson sade:
And those errors are?
This is the compile error I get.
c:\Documents and Settings\Tony\kau\cplusplus\test15\base.h(15): error
C2143: syntax error : missing ';' before 'public'
I don't. And I'm guessing you use VC++ since it (some broken version of
it) allows you to give a pure virtual member function a body.
If you include something directly before the class definition the actual
error could be there instead, which propagates causing the syntax error.
How can main be used with this clone function?
int main(int argc, char* argv[])
{
Sub * s = new Sub;
delete copyObject(*s);
delete s;
return 0;
}
//Tony
Tobias
Tobias,
You declared Clone in class Sub as pure virtual with the "=0" at the end of
the declaration. By doing that, you are telling the compiler that it should
be illegal to instantiate an object of type Sub, which is the very thing you
are trying to do in the Clone member function.
Although it was previously pointed out that a pure virtual function can have
a body, which can be called statically (as opposed to dynamically through a
pointer), the presence of a body of a pure virtual function is rarely
necessary. In most cases, a member function is declared pure virtual when
the concept conveyed through the class is so abstract, that it is impossible
to give a solid definition to such a member function. An example would be
the draw function in the abstract class shape. Drawing an abstract shape is
meaningless, in fact.
Ben