无法使用指针访问类函数
Unable to access class function using pointers
当试图访问我的类成员的函数时,我无法在使用指针时找到它们。这构成了一个更大项目的一部分,并尽可能地简化了问题。注意,错误发生在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;
}
使用括号避免歧义:
((*thisone)[1]).getIDnumber();
你也可以做
thisone->operator[](1).getIDnumber();
同时,在声明时也要这样写:
int getIDnumber();
代替int Person::getIDnumber();
。在声明成员函数时不应该使用解析操作符。
相关文章:
- 从不同C++类的成员变量访问成员函数
- 无法访问基类函数 C++
- 从父类的向量访问子类函数,而无需向下转换
- 访问另一个类中的模板化嵌套类函数和对象
- 如何在构造函数中访问类变量以分配它们,而无需在C++中使用此指针
- 是否可以访问类数据成员并在析构函数中对它们执行操作?
- C++ 基类调用已删除或无法访问的函数
- 我相信这是 clang++ 中的一个错误,与访问类的公共成员函数有关
- 无法访问派生类函数内的基类的受保护数据成员
- Lambda 函数,用于调用有权访问类成员的成员函数
- C++友元函数无法访问类的公共函数
- 访问成员函数中参数的类成员
- 如何从 C++ 中的主函数访问类中的私有构造函数?
- 我设计了一个类并创建了基指针,但是当我尝试通过基指针访问派生函数时,它会出错
- C++ 从未在其中定义的函数访问类
- 尝试访问类向量中的函数,而不更改向量的私有状态
- 如何从另一个类正确访问类函数
- 如何访问类函数中的向量
- 使用:访问类函数
- 无法使用指针访问类函数