J
Jason Heyes
Why does Foo.h need to be included in Bar.cpp for this program to compile
properly? I define the FooList destructor in a separate module so that a
forward declaration to Foo can be used.
// FooList.h
#include <vector>
class Foo;
class FooList
{
std::vector<Foo> v;
public:
~FooList(); // destructor interface
};
// FooList.cpp
#include "FooList.h"
#include "Foo.h" // destructor definition this
FooList::~FooList() { }// destructor definition
// Bar.cpp
#include "FooList.h"
int main()
{
FooList foos;
return 0;
}
Error Message
==========
Bar.cpp
c:\program files\microsoft visual studio\vc98\include\vector(59): error
C2036: 'Foo *': unknown size
c:\program files\microsoft visual studio\vc98\include\vector(58): while
compiling class-template member function 'vector<Foo>::~vector<Foo>(void)'
I don't want to include Foo.h in Bar.cpp unless I have to. Do I have to? If
so, why? Thanks a bunch.
properly? I define the FooList destructor in a separate module so that a
forward declaration to Foo can be used.
// FooList.h
#include <vector>
class Foo;
class FooList
{
std::vector<Foo> v;
public:
~FooList(); // destructor interface
};
// FooList.cpp
#include "FooList.h"
#include "Foo.h" // destructor definition this
FooList::~FooList() { }// destructor definition
// Bar.cpp
#include "FooList.h"
int main()
{
FooList foos;
return 0;
}
Error Message
==========
Bar.cpp
c:\program files\microsoft visual studio\vc98\include\vector(59): error
C2036: 'Foo *': unknown size
c:\program files\microsoft visual studio\vc98\include\vector(58): while
compiling class-template member function 'vector<Foo>::~vector<Foo>(void)'
I don't want to include Foo.h in Bar.cpp unless I have to. Do I have to? If
so, why? Thanks a bunch.