By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,939 Members | 1,546 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,939 IT Pros & Developers. It's quick & easy.

Inheritance declaration

P: n/a
my header file looks like this:

class A;
class B;
class C;

class A
{
....
};

class B:public A
{
private:
B doSomething(A& a);
public:
B processMe(C c){...; doSomething(c);} // Problematic statment
};

class C: public A
{
....
}

The problem is that by the time it reaches the line of code with the
problematic statement, it hasn't declared yet that C indeed extends A.
Is there any way on how I can declare this? Or any other possible
options if i can't?

Oct 9 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
<ja****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
: my header file looks like this:
:
: class A;
: class B;
: class C;
:
: class A
: {
: ....
: };
:
: class B:public A
: {
: private:
: B doSomething(A& a);
: public:
: B processMe(C c){...; doSomething(c);} // Problematic statment
: };
:
: class C: public A
: {
: ....
: }
:
: The problem is that by the time it reaches the line of code with the
: problematic statement, it hasn't declared yet that C indeed extends A.
: Is there any way on how I can declare this? Or any other possible
: options if i can't?

You have to provide the definition(=implementation)
of processMe after class C has been seen, for example:

class B:public A
{
private:
B doSomething(A& a);
public:
B processMe(C c); // (forward-)declaration
};

class C: public A
{
....
};

B A::processMe(C c) {...; doSomething(c);} // definition

(you could use reinterpret_cast, but this would formally be UB)
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com

Oct 9 '06 #2

P: n/a

Ivan Vecerina wrote:
<ja****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
: my header file looks like this:
:
: class A;
: class B;
: class C;
:
: class A
: {
: ....
: };
:
: class B:public A
: {
: private:
: B doSomething(A& a);
: public:
: B processMe(C c){...; doSomething(c);} // Problematic statment
: };
:
: class C: public A
: {
: ....
: }
:
: The problem is that by the time it reaches the line of code with the
: problematic statement, it hasn't declared yet that C indeed extends A.
: Is there any way on how I can declare this? Or any other possible
: options if i can't?

You have to provide the definition(=implementation)
of processMe after class C has been seen, for example:

class B:public A
{
private:
B doSomething(A& a);
public:
B processMe(C c); // (forward-)declaration
};

class C: public A
{
....
};

B A::processMe(C c) {...; doSomething(c);} // definition

(you could use reinterpret_cast, but this would formally be UB)
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com
Ahhh.. thanx!

Oct 9 '06 #3

P: n/a
ja****@gmail.com wrote:
my header file looks like this:

class A;
class B;
class C;

class A
{
....
};

class B:public A
{
private:
B doSomething(A& a);
public:
B processMe(C c){...; doSomething(c);} // Problematic statment
};

class C: public A
{
....
}

The problem is that by the time it reaches the line of code with the
problematic statement, it hasn't declared yet that C indeed extends A.
Is there any way on how I can declare this? Or any other possible
options if i can't?
Is there a particular reason that you're passing C by value rather than
by const reference? If you use a reference, you can do this:

class C;

class B : public a
{
///
public:
B processMe(const C&);
};
Also, separate the declaration and defintion of B::processMe().

Oct 9 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.