views:

314

answers:

4

From what I can gather from Google, I must have syntax/parsing error but I can't seem to locate it..

This is my header file:

#include <fstream>
#include <iostream>
#include <vector>

#ifndef DATA_H
#define DATA_H
#include "Data.h"
#endif

vector<Data*> DataReader();   // This is line 11, where the error is..

And this is the .cpp file:

#include "DataReader.h"

using namespace std;

vector<Data*> DataReader()
{
 .....
}

I skipped the content of the DataReader() because I thought it was irrelevant but I can post it if needed. Below is the error that I get:

DataReader.h:11: error: expected constructor, destructor, or type conversion before '<' token

Thanks for any input/suggestions.

+3  A: 

In your header file, you need to explicitly use std::vector rather than just vector.

Also, I'm guessing that "Data.h" contains statements of the form:

#ifndef DATA_H
#define DATA_H
...
#endif

That's fine, but you should not use these include guards across #include "Data.h" as well, only within the file itself.

Paul Baker
i.e. have thse #ifndef ... #define .... at the top of Data.h itself, and #endif at this end of this file. (So all possible files referencing this header do not need to write these few lines). This is just a style hint, no relation to the compilation error, however.
mjv
It's critical important that you don't have the `#define` line before the `#include` if the included file has `#ifndef` guards base on the same macro as the outer `#ifndef` guards otherwise the contents of the header file will never be included.
Charles Bailey
+4  A: 

In your header file you need to use std::vector and not plain vector in the declaration of the function DataReader.

The standard include <vector> causes the vector class template to be defined in the std namespace and the declaration in your header file happens before any using namespace std; or using std::vector;.

Charles Bailey
+4  A: 

I think in your header you probably need to write std::vector<Data*> DataReader(); as the using namespace std; is not in scope.

SteveL
+1  A: 

Use std:vector and not vector before Datareader.

RC