home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!timbuk.cray.com!hemlock.cray.com!augs
- From: augs@cypress45.cray.com (Paul Algren)
- Subject: Why won't this C++ compile?
- Message-ID: <1993Jan25.105518.8645@hemlock.cray.com>
- Originator: augs@cypress45
- Lines: 95
- Sender: augs@cypress45 (Paul Algren)
- Nntp-Posting-Host: cypress45
- Organization: Cray Research, Inc.
- Date: 25 Jan 93 10:55:18 CST
-
-
- Any comments would be interesting on the following code sequence.
-
- Given the following files:
-
- // ############# class1.h ##################
- class class2;
-
- class class1 {
- class2* other;
-
- public:
- class2* class2() {
- return (other);
- }
- void SetClass2(class2*);
- };
-
- // ############# class2.h ##################
- class class1;
-
- class class2 {
- class1* other;
-
- public:
- class1* class1() {
- return (other);
- }
- void SetClass1(class1*);
- };
-
- // ############# class1.c ##################
- #include <class1.h>
- #include <class2.h>
-
- void
- class1::SetClass2(class class2* c)
- {
- other = c;
- }
-
- // ############# class2.c ##################
- #include <class2.h>
- #include <class1.h>
-
- void
- class2::SetClass1(class1* c)
- {
- other = c;
- }
-
- I compile class1.c (CC -c -I. class1.c) and get no errors, but I compile
- class2.c and I get the following errors.
-
- (2.1)
- CC -c -I. class2.c
- "class2.c", line 5: warning: old style definition of SetClass1() (anachronism)
- "class2.c", line 8: error: name expected in argument list
- "class2.c", line 5: error: class2::SetClass1() type mismatch: void class2::(class1 *) and void class2::()
- Compilation failed
-
- Does someone have an explanation for this?
- I can't seem to imagine why the compiler searches the symbols finding
- class2::class1() first or at all instead of searching for known classes (types).
-
- The fix in class1.c is to add the class specifier before the classname
- explicitly telling the compiler to expect a class name instead of a
- symbol, but why?
-
- When using 3.0 I have the same problem, but there is now another error on the
- declaration in the include files. Now neither class1.c nor class2.c will
- compile.
-
- (3.0)
- CC-3.0.1 -c -I. class2.c
- "./class2.h", line 13: error: initializer for member SetClass1
- "./class2.h", line 13: error: bad base type: void SetClass1
- "./class1.h", line 13: error: initializer for member SetClass2
- "./class1.h", line 13: error: bad base type: void SetClass2
- "class2.c", line 5: warning: old style definition of SetClass1() (anachronism)
- "class2.c", line 6: error: name expected in argument list
- "class2.c", line 5: error: class2::SetClass1() is not a member of class2
- Compilation failed
-
- C-3.0.1 -c -I. class1.c
- "./class1.h", line 13: error: initializer for member SetClass2
- "./class1.h", line 13: error: bad base type: void SetClass2
- "./class2.h", line 13: error: initializer for member SetClass1
- "./class2.h", line 13: error: bad base type: void SetClass1
- "class1.c", line 5: error: class1::SetClass2() is not a member of class1
- Compilation failed
-
- ??????,
-
- Paul
-