【问题标题】:C++: class "X" has no member named "Y"C++:类“X”没有名为“Y”的成员
【发布时间】:2013-08-02 16:04:14
【问题描述】:

我有两个项目:项目 A项目 B。 在项目 A 中,我有以下课程:1.

我已经使用“#include '1' 和使用 eclipse 中的配置包含了项目 A 中的类 '1'。

当我尝试从项目 B 中的类 1 访问公共方法时,出现错误: “A”类没有名为“Test”的成员。

我做错了什么???

编辑:类名和方法用于骨架目的。

项目“MGeneral”有一个名为“MGeneralCommands”的类 -

class MGeneralCommands
{
    public:

        void sendCommand(TCPSocket * sock,int command);
        void sendData(TCPSocket * sock,string data);
        int readCommand(TCPSocket * sock);
        string readData(TCPSocket * sock);
};

项目“MSA”有一个名为“TCPMessengerServer”的类,我在其中使用了“#include "MGeneralCommands.h"”。例如,当尝试调用方法“sendCommand”时,它不会识别它。

【问题讨论】:

  • 请提供代码。
  • 请考虑至少显示您的代码大纲 - 只是骨架
  • 你的班级名称应该是“1”吗?
  • 您能告诉我们尝试调用该方法的代码吗?这可能就是问题所在。
  • @Erez:您需要在 MGeneralCommands:commands.sendData(socket,"Test"); 或类似类型的对象上调用该方法。

标签: c++ eclipse configuration include


【解决方案1】:

从 cmets 来看,错误实际上是完全不同的:

‘sendData’ was not declared in this scope

来自代码

sendData(socket,"TEST");

除非您已经在 MGeneralCommands(或子类)的成员函数中,否则您将需要该类型的对象来调用它:

commands.sendData(socket,"TEST");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多