forward declaration related problem
From: exits funnel (exitsfunnel_at_NOSPAMyahoo.com)
Date: 11/30/03
- Next message: arenaTR: "NEWBIE: compilation trouble!!!"
- Previous message: Gianni Mariani: "Re: Finding the levels of a Binary tree"
- Next in thread: David Fisher: "Re: forward declaration related problem"
- Reply: David Fisher: "Re: forward declaration related problem"
- Reply: Victor Bazarov: "Re: forward declaration related problem"
- Reply: Dave O'Hearn: "Re: forward declaration related problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 Nov 2003 23:43:45 GMT
Hello,
I have the following code:
class A
{
public:
A(int i = 0):asInt(i) { }
operator B( ) { return B(asInt); }
private:
int asInt;
};
class B
{
public:
B(int i = 0):bsInt(i) { }
operator A( ) { return A(bsInt); }
private:
int bsInt;
};
int main( )
{ }
When I try to compile it my compiler has this to say:
> test.cpp:5: parse error before `('
> test.cpp:5: syntax error before `('
> test.cpp:7: semicolon missing after declaration of `A'
> test.cpp:7: parse error at null character
> test.cpp: In method `A::A (int)':
> test.cpp:4: class `A' does not have any field named `asInt'
> test.cpp: At top level:
> test.cpp:7: parse error at null character
The problem is obviously that when the compiler hits the reference to B
in A it doesn't yet know anything about A. So I add this:
class B;
to the very beginning of the file and now my compiler rebuts with:
> test.cpp: In method `A::operator B ()':
> test.cpp:7: return type `class B' is incomplete
> test.cpp:7: invalid use of undefined type `class B'
> test.cpp:1: forward declaration of `class B'
I understand the issue here, but I'm not sure how to solve it. If
anyone could point me in the right direction I'd really appreciate it.
Thanks in advance.
-exits
- Next message: arenaTR: "NEWBIE: compilation trouble!!!"
- Previous message: Gianni Mariani: "Re: Finding the levels of a Binary tree"
- Next in thread: David Fisher: "Re: forward declaration related problem"
- Reply: David Fisher: "Re: forward declaration related problem"
- Reply: Victor Bazarov: "Re: forward declaration related problem"
- Reply: Dave O'Hearn: "Re: forward declaration related problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|