Jul 9, 2010 at 2:28pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
class one {
public :
void test(two t) {
}
};
class two {
public :
void testt(one o) {
}
};
int main() {
return 0;
}
this gives the following error in visual c++ :
(3)error C2061: syntax error : identifier 'two'
how do i fix such a thing.
Last edited on Jul 9, 2010 at 2:31pm UTC
Jul 9, 2010 at 2:42pm UTC
Need to use incomplete class def.
Add following to top of file (before class one definition)
class two;
Jul 9, 2010 at 2:44pm UTC
gives me this error :
1 2
test.cpp(7): error C2027: use of undefined type 'two'
test.cpp(1) : see declaration of 'two'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
class two;
class one {
public :
void test(two t) {
}
};
class two {
public :
int b;
void testt(one o) {
}
};
int main() {
return 0;
}
Last edited on Jul 9, 2010 at 2:44pm UTC
Jul 9, 2010 at 3:29pm UTC
If you pass by pointer or reference, the complete type will not be required. Try void test(const two & t) {
.
Jul 9, 2010 at 4:31pm UTC
If you ignore wasabi's post and do what moorecm suggested it will compile.
EDIT: you'll need to move the body of one::test() to below class two's declaration also.
Last edited on Jul 9, 2010 at 4:32pm UTC