ToAsadfa
ToAsadfa

Reputation: 21

Error 42: Symbol Undefined

I was trying to program a little program in D, but I keep getting linking errors (although I don't use external libraries). The exact error message is Error 42: Symbol Undefined _D4main4mainFAAyaZv6clientMFZC6client6Client. My code is

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);
}

Upvotes: 2

Views: 214

Answers (1)

Vladimir Panteleev
Vladimir Panteleev

Reputation: 25197

Client client();

In D, this will declare a function with no arguments, which returns a Client instance.

client.register(d);

This will attempt to call the declared function. However, since it has no body, the program will compile, but will fail to link, as the linker will be unable to find the function's body.

You probably meant:

auto client = new Client();

Upvotes: 4

Related Questions