Kobojunkie
Kobojunkie

Reputation: 6545

C++ Build Error- expected class-name before '{' token|

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

Answers (3)

Void - Othman
Void - Othman

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:

  • if namespace pollution is an issue (e.g. #define collides with Collection)
  • if the 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

cadizm
cadizm

Reputation: 946

I think you could also forward declare Collection:

class Collection;

class VariableArray : public Collection {
....
};

Upvotes: 0

R Samuel Klatchko
R Samuel Klatchko

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

Related Questions