Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STL Classes in header files

Status
Not open for further replies.

jsteel

Programmer
Feb 11, 2005
17
0
0
US
Im trying to create a class with a vector and a list. It gives me 8 errors, starting with error C2143: syntax error : missing ';' before '<', when i try and dclare either in the header file. Ive included <vector> and <list> in the cpp. I can declare them in the cpp as well. Im using VS6. Ive tried it with and without std::.

Thank You
 
Show your code and the line the error(s) refer to.
 
#ifndef GRAPH
#define GRAPH

class CGraph;
class CListGraph;
class CMatrixGraph;

class CGraph {
public:
CGraph() { }
...
};

class CListGraph : public CGraph {
public:
CListGraph() { }
CListGraph(int nNumVertices);
...
private:

};

class CMatrixGraph : public CGraph {
public:
CMatrixGraph() { }
CMatrixGraph(int nNumVertices);
...

private:
vector<int> vertices;
};

#endif

Upon running I get these errors which all refer to the last line 'vector<int> vertices';

error C2143: syntax error : missing ';' before '<'
error C2501: 'vector' : missing storage-class or type specifiers
error C2059: syntax error : '<'
error C2238: unexpected token(s) preceding ';'
GraphBuilder.cpp
error C2143: syntax error : missing ';' before '<'
error C2501: 'vector' : missing storage-class or type specifiers
error C2059: syntax error : '<'
error C2238: unexpected token(s) preceding ';'
Error executing cl.exe.

Graph.exe - 8 error(s), 0 warning(s)
 
In your original post, you said you've included <vector>, but in the code there is no #include <vector>. Add it. In your original post you said you tried it with the std::, but in the code there is no std::vector. Add it.
 
Ive tried all combinations of adding the include and std::. The code I gave is in the header. I have to #include in the cpp file which consists of just a mian method right now. Putting the include in the header doesnt work either.
 
Sure it will. The #include <vector> should go in the header file just below "#define GRAPH". Everywhere you put vector in the header file you should replace it with std::vector. If there is still a problem, post the code with those changes made and the error's with line numbers (and point out which lines are which if you remove parts - don't remove the lines before and after the errors).
 
That did work. My Bad. I thought I had tried that combination. Thanks a lot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top