I have a class which def开发者_如何学运维ines the following members in a header file (.hpp):
public :
int loadData(char* filename);
private :
std::vector<vertex> vertices;
std::vector<triangle> triangles;
std::vector<frame> frames;
The vertex
, triangle
and frame
are structures defined in another header file included in this header file.
Now, in the definition of the function loadData
in the .cpp, I cannot access the members vertices
, triangles
and frames
. For example, I have the following code resulting in the error shown under it:
cout << "total vertices stored= " << vertices.size() << endl;
motionViewer.cpp:59: error: 'vertices' was not declared in this scope
Why cannot I access these members?
Thank you for the help.
A blind shot: because you forget to put the class-name before the loadData-method in your .cpp:
int className::loadData(char* filename)
But to be sure you need to show more code.
Are you sure you haven't missed the ::
? In the cpp:
#include "header_name.h"
ClassName::loadData( ..
//...
Probably you forgot to use the (class) scope in the cpp file.
Like:
void motionViewer::loadData(char* filename)
{
// ...
}
Assuming the name of the class is motionViewer
.
- do your define your structures in another namespace?
- have you missed the class scope for the definition of the function?
- have you correctly defined your structures (like not missing the tail semicolon) ?
精彩评论