Reputation: 6545
I have the class below which inherits from a Collection class where I have virtual functions defined that I need to later on implement in my derived class below. I have yet to include the definitions for my member functions, except for the constructor of my derived class, in the .cpp file. However when I build my project, I get the following error message
expected class-name before '{' token|
I have tried everything I know to try, and am in need of assistance in understanding what I have wrong in my code and how I can go about fixing it.
#ifndef VARIABLEARRAY_H
#define VARIABLEARRAY_H
#include "Collection.h"
using namespace std;
class VariableArray: public Collection{
int* list[];// dynamic array that is resized on demand
public:
VariableArray();
};
#endif
any help will be greatly appreciated.
Upvotes: 1
Views: 1145
Reputation: 3481
How did you determine if Collection
is available to the compiler? Does the class
declaration for Collection
show up in the preprocessed output of your VariableArray.cpp
file, or whatever the corresponding source file is?
Looking at the preprocessed output can help you determine:
#define
collides with Collection
)Collection
declaration is truly available before your VariableArray
declaration.If it's not a namespace pollution issue, I'd check if you are using the same #include
guards in more than one header file.
Upvotes: 0
Reputation: 946
I think you could also forward declare Collection:
class Collection;
class VariableArray : public Collection {
....
};
Upvotes: 0
Reputation: 76531
Are you sure the Collection
symbol has already been seen by your translation unit?
You may want to add:
#include "Collection.h"
(or whatever the correct name is) before the class definition.
Upvotes: 1