E
exits funnel
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:
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:
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
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:perator 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