forward declaration error
From: Scott (scott_at_nospam.com)
Date: 05/29/04
- Next message: Mike Wahler: "Re: forward declaration error"
- Previous message: Kenny: "Re: operator function"
- Next in thread: Mike Wahler: "Re: forward declaration error"
- Reply: Mike Wahler: "Re: forward declaration error"
- Reply: EventHelix.com: "Re: forward declaration error"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 May 2004 00:28:25 GMT
Hi All,
I am trying to understand the following errors, and hope someone can help
me along. This is code not originally written by me, but that I am
trying to fix and compile. I have the following in a single file:
#include "A.h"
class foo;
class B : public A
{
public:
foo * getFooPtr() { return fooObject; }
protected:
foo * fooObject;
};
template <class T>
int compare( const T * first, const T * second )
{
foo * object = first->getFoo();
int number = foo->getNum();
}
It compiles with errors:
error: invalid use of undefined type `struct foo'
error: forward declaration of `struct foo'
I believe this is because the forward declaration of foo doesn't actually
provide any information on what functions are contained within foo, so I
need to change:
class foo;
to
#include "foo.h"
Correct?
However, when I do that, I get:
error: ISO C++ forbids declaration of `foo' with no type
error: `foo' undeclared (first use this function)
The first referring to the use of foo in class B, and the second to the
use of foo in the template function. I am confused, foo is declared in
foo.h, so why the errors? Please help!
Best,
Scott
- Next message: Mike Wahler: "Re: forward declaration error"
- Previous message: Kenny: "Re: operator function"
- Next in thread: Mike Wahler: "Re: forward declaration error"
- Reply: Mike Wahler: "Re: forward declaration error"
- Reply: EventHelix.com: "Re: forward declaration error"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|