"*"标记之前的预期非限定 id:指向成员函数的指针
Expected unqualified-id before '*' token: Pointer to Member Functions
我正在尝试运行此代码,但无法理解是什么导致了错误。
#include <iostream>
using namespace std;
class Shape
{
public:
void show ( float ) { cout << "Hello"; }
};
int main ( )
{
void (Shape::*FPtr2) (float) = &Shape :: show;
(Shape::*FPtr2)(1.1);
return 0;
}
调用非静态成员函数需要一个对象。通过指向成员函数的指针调用非静态成员函数也需要一个对象。
#include <iostream>
using namespace std;
class Shape
{
public:
void show ( float ) { cout << "Hello"; }
};
int main ( )
{
void (Shape::*FPtr2) (float) = &Shape :: show;
Shape myShape; // here is my object
(myShape.*FPtr2)(1.1); // here is the call to the object's show function via pointer
return 0;
}
相关文章:
- 1d 智能指针不适用于语法 (*)++
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 为什么使用 "this" 指针调用派生成员函数?
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用指针从C++中的数组中获取最大值
- 助记符和指向成员语法的指针
- C++:"("令牌"之前有预期的非限定 id 指向类中成员函数的指针
- 类型ID指针和引用比较差异?
- 使用来自 unique_ptr 向量的原始指针作为排序的 ID
- 使用宏访问指向数据成员的指针会导致"error: expected unqualified-id before ‘*’ token"
- 如何查找 CoreWindow 的所有指针 ID
- 通过指针对基函数进行限定 id 调用
- 通过指针访问类的成员时"unqualified-id"编译器错误
- MAKEINTRESOURCE 返回资源 ID 的错误指针
- "*"标记之前的预期非限定 id:指向成员函数的指针
- 为什么OpenGL在创建/释放资源时使用指向资源id的指针
- 多态指针的类型id
- 我应该为我的不透明对象使用整数ID还是指针?
- 使用整型指针作为唯一id有多糟糕?c++ 11
- 如何在运行时检查类型id是否为指针