请求 [..] 中的成员 [..],该成员属于非类类型 [..]
Request for member [...] in [...], which is of non-class type [...]
我已经在互联网上搜索了这个编译错误的解决方案。他们中的大多数似乎与两个选项有关:
- 将指针视为对象,而不是取消引用它。
- 将变量与返回变量类型的函数误认为并尝试访问它。
我的代码是:
#ifndef ESCRITOR_PROLOG_HH
#define ESCRITOR_PROLOG_HH
#include "planning.hh"
#include <string>
#include <ostream>
class EscritorProlog {
private:
Planning planningAEscriure;
public:
EscritorProlog(Planning planning);
EscritorProlog(Planning &&planning);
void escriuFitxerProlog(std::ostream &escritor);
};
#endif
main.cc:
#ifndef MAIN_CC
#define MAIN_CC
#include "escritorProlog.hh"
#include <iostream>
#include <fstream>
int main () {
std::ofstream escritor("./test.txt");
EscritorProlog test(Planning());
test.escriuFitxerProlog(escritor);
}
#endif
如果您尝试使用
g++ -c main.cc -std=c++11
你只会得到错误...
main.cc: In function ‘int main()’:
main.cc:11:8: error: request for member ‘escriuFitxerProlog’ in ‘test’, which is of non-class type ‘EscritorProlog(Planning (*)())’
test.escriuFitxerProlog(escritor);
现在我不知道我是否遗漏了一些东西,但我在我的代码中看不到之前提到的两个问题中的任何一个。如果我公然失明或其他任何东西,我很抱歉,但我只是没有看到错误。
任何帮助将不胜感激。
这是最令人烦恼的解析实例。
您可以使用列表初始化来修复它,这在以下上下文中是明确的:
EscritorProlog test(Planning{});
不幸的是,您有来自Planning
的模棱两可的EscritorProlog
结构:
EscritorProlog(Planning planning); // (1)
EscritorProlog(Planning &&planning); // (2)
假设您要为 (1)
定义一个复制构造函数,请将签名更改为
EscritorProlog(const Planning& planning);
以避免歧义。通过这些更改,您的代码将进行编译。
魔杖盒示例
相关文章:
- 根据模板类型选择类模板的成员类型?
- 函数模板签名中忽略的成员类型def 的访问说明符
- 在C++如何从数组中提取成员并返回成员类型的数组?
- C++从成员类型中扣除类型的功能模板?
- 无法初始化以 std::byte 作为成员类型的位字段
- 构造函数可以更改默认成员类型吗?
- 使用相同方法但不同成员类型构建类的最佳方法
- 允许通过指向方法的成员参数的指针来推断模板参数所指向的成员类型
- 使用 std::条件根据模板参数选择成员类型
- CRTP:如何推断要用作返回类型的成员类型?
- 对成员类型的成员方法使用 std::result_of<>
- C :可以从类及其受保护的成员类型继承可以继承吗?
- 如何在不指定不必要的模板参数的情况下使用模板类的成员类型
- 基类数据成员类型取决于派生类
- C 多态性:允许模棱两可的成员类型
- 使用使用成员类型别名的构造函数来推论类模板参数
- 获取与在模板参数中传递的函数成员类型相同的类
- 如果静态成员未初始化并且成员类型是类本身,该怎么办?
- boost::bind 无法绑定到纯虚拟基类中定义的非静态函数模板成员类型
- 将联合强制转换为其成员类型之一