I want to use the STL vector to store an array of objects which class is user-defined. LMVector is the user defined class and here it's the LMVector.h file.
class LMVector
{
private:
....
public:
....
};
In another class LMRectangle, there is a field needed to store an array of LMVector. Here is the header file for LMRectangle
class LMRectangle{
public:
....
private:
std::vector<LMVector> _vertexList;
....
}
This doesn't work and it will complain that LMVector is a undeclared identifier. Here are the complier errors:
e:\C++ Projects\Topology\LMRectangle.h(25): error C2065: 'LMVector' : undeclared identifier
e:\C++ Projects\Topology\LMRectangle.h(25): error C2955: 'std::vector' : use of class template requires template argument list
e:\C++ Projects\Topology\LMVector.cpp(21): error C2371: 'LMVector' : redefinition; different basic types
Could somebody solve this problem for me please Thanks very much!!!

vector container with user-defined class problem
windark
You need to #include LMVector.h within LMRectangle.h. Or, if you can store LMVector * instead, you can put 'class LMVector;' at the top of the header, and include the lmvector.h in your cpp file. I like that better, because including one header shouldn't include others if you can help it.
BonnieB
yeah I tried to include the LMVector.h within LMRectangle.h, but it doensn't work. And still give me the error that is
e:\C++ Projects\Topology\LMRectangle.h(7): error C2011: 'LMRectangle' : 'class' type redefinition
I don't know why.
OliverK
Manurein
Sounds to me like you have two files which include each other. The solution is to do the other thing I said, make it a vector of pointers, forward declare the class, and put the include in your cpp file. The other solution is to #include it only once, in your stdafx, so it's visible everywhere.