На самом деле существует способ получить это поведение. "Каждая проблема в программном обеспечении может быть решена с уровнем абстракции".
/* Disclaimer: I haven't done C++ in many months now, there might be a few syntax errors here and there. */
class parent
{
public:
parent( ) { /* nothing interesting here. */ };
protected:
struct parent_virtual
{
virtual void do_something( ) { cout << "in parent."; }
};
parent( const parent_virtual& obj )
{
obj.do_something( );
}
};
class child : public parent
{
protected:
struct child_virtual : public parent_virtual
{
void do_something( ) { cout << "in child."; }
};
public:
child( ) : parent( child_virtual( ) ) { }
};
Хорошо , Я не знаю точной проблемы, но для начала:
См. Также: c ++ faq lite
In addition to what Johan said, you cannot have a separate definition and declaration for the function even if both are in the same header file. This holds true especially for member functions of classes. The function code should be of the form:
class someClass
{
void someFunc()
{ ... }
}
// This will make the function inline even w/o the explicit 'inline'
And NOT of the form
class someClass
{
public:
void someFunc();
}
void someClass::someFunc()
{ ... }