Sup peeps, hope you guys can give a mate a hand with this default constructor problem. I get this error when i instantiate a class:
error LNK2019: unresolved external symbol...

This is my LavaLand.h

...

class LavaLand 
{

    highscore &h;

public:

    LavaLand();

    void setup();

};


...

LavaLand.cpp

void LavaLand::setup()
{       
    ...
    h.scoreboard(getScore());

}

I call this setup() in my Game.cpp

void Game::update()
{
        switch (myInput) {

        case 1: {
            LavaLand ll;   <--------- error
            ll.setup()
            break;
        }

}

It has a default constructor but i'm thinking theres something wrong with it though. Hope someone here could help. If you need more code please let me know.
Cheers

Recommended Answers

All 5 Replies

If you want LavaLand to have a default generated constructor then you need to get rid line 8 in LavaLand.h. You could also just change line 8 to LavaLand() {}; to make a default constructor yourself.

I've actually tried this. When i remove it an error stating " 'Lavaland': no appropriate default constructor available"

or if i simply code it as LavaLand() {}; i'd get an error of..."
Syntex error: '{'
'Lavaland::h' must be initialized in constructor base/member initializer list.
See declaration of 'Adventure::h

which prompted me to put highscore &h in the list of

LavaLand():
    {
        highscore &h;
    }

but, that too didn't work.

You have a reference member (highscore) in LavaLand and that needs to be initialized upon creation. Either remove the reference or change the constructor to take in a value to initialize highscore.

I'd like to keep the reference so i've initialized by...

class LavaLand
{

public:
    highscore &h;

    Lavaland(highscore &hs) :
        h(hs)
    {}

but it results in the same error " 'Lavaland' : No appropriate default constructor available"

i see that i forgot to call the right LavaLand ll; should be LavaLand ll(hs)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.