开发者

Accessing std::vector data members of a class from its member functions

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.


  1. do your define your structures in another namespace?
  2. have you missed the class scope for the definition of the function?
  3. have you correctly defined your structures (like not missing the tail semicolon) ?
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜