开发者

"Expected constructor, destructor, or type conversion before '<' token"

I'm running into a syntax/parsing error, but I can't seem to locate it.

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

Here is DataReader.h:

#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:

#inclu开发者_Python百科de "DataReader.h"

using namespace std;

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

I skipped the content of DataReader() because I think it's irrelevant, but I can post it if needed.

Thanks for any input/suggestions.


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.


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;.


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


Use std:vector and not vector before Datareader.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜