【发布时间】:2016-10-04 09:39:38
【问题描述】:
在尝试访问我的类成员的功能时,使用指针时找不到它们。这是一个更大项目的一部分,并尽可能简化了问题。请注意,错误发生在 void getthenumberhere... 内部,无法检测到 getIDnumber 函数:
#include <iostream>
#include <stdlib.h>
#include <vector>
#include "windows.h"
#include <stdio.h>
//#include <math.h>
#include <string>
using namespace std;
class Person
{
public:
Person(int);
~Person();
vector<RECT>* processrectangles;
int Person::getIDnumber();
private:
int IDnumber;
};
Person::Person(int x)
{
IDnumber = x;
}
Person::~Person()
{
}
int Person::getIDnumber() {
return IDnumber;
}
void getthenumberhere(vector<Person>* thisone) {
int outID = *thisone[1].getIDnumber(); //IT CANT FIND THIS FUNCTION
}
int main() {
int NextID = 1;
vector<Person> People;
Person newguy(1);
People.push_back(newguy);
getthenumberhere(&People);
return 0;
}
【问题讨论】:
-
在编程中以
0开始计数,所以应该使用(*thisone)[0].getIDnumber() -
只是一个评论:如果你在做 C++,包括
cstdlib和cstdio而不是stdlib.h和stdio.h(和cmath而不是math.h如果你取消注释行)
标签: c++ function class pointers