【问题标题】:Error 42: Symbol Undefined错误 42:符号未定义
【发布时间】:2014-08-06 10:15:29
【问题描述】:

我试图在 D 中编写一个小程序,但我不断收到链接错误(尽管我不使用外部库)。确切的错误消息是Error 42: Symbol Undefined _D4main4mainFAAyaZv6clientMFZC6client6Client。我的代码是

interface Component
{
public:
    string GetIdentifier();
    void Activate(JSONValue data);
}

class SomeComponent : Component
{
public:
    string GetIdentifier()
    {
        return "SomeComponent";
    }
    void Activate(JSONValue data)
    {
        writeln("Something");
    }
}

class Client
{
public:
    Component[] components;
    void register(Component c)
    {
        components ~= c;
        writeln(c.GetIdentifier());
    }
}

void main(string[] args)
{
    Client client();
    SomeComponent d;
    client.register(d);
}

【问题讨论】:

    标签: linker d


    【解决方案1】:
    Client client();
    

    在 D 中,这将声明一个不带参数的函数,该函数返回一个 Client 实例。

    client.register(d);
    

    这将尝试调用声明的函数。但是,由于它没有函数体,程序将编译,但无法链接,因为链接器将无法找到函数体。

    你的意思可能是:

    auto client = new Client();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-10
      • 2013-10-22
      • 2014-06-01
      • 2015-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多