Topic: Forward declaration of a sub-class?
Author: bwmott@unity.ncsu.edu
Date: 1996/02/06 Raw View
I posted this to comp.std.c++, but I guess I was supposed to mail it
so I'm mailing it now :-)
[ Posting should work. If it doesn't, contact your site administrator
to find out why. -mod ]
--------------------------------------------------------------------------
I've got a question about forward declaring a class as a sub-class of
another class. Is it possible under the C++ draft standard to do
something like:
class S;
class T : public S;
The reason I need such a thing is because of the restrictions placed on
redefining the return type of a virtual function.
A simplified version of my class layout is:
class S;
class T; // This should be something to tell the compiler that
// class T exists and that it's a subclass of S.
class A {
public:
virtual S& belong() = 0;
};
class B : public A {
public:
virtual T& belong(); // This doesn't work but it seems
// that it should be possible!
private:
T& myT;
};
class S {
public:
virtual A& get() = 0;
};
class T : public S {
public:
virtual B& get(); // This works fine
private:
B& myB;
};
I guess a possible solution would be for the redefinition test to be done
on the definition instead of on the declaration.
Is there any hope?
Thanks,
Bradford Mott
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is
summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
]