# linker error i dont quite understand

This topic is 3935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

GameMaterial.obj : error LNK2001: unresolved external symbol "public: __thiscall Material::Material(void)" (??0Material@@QAE@XZ) is what i keep getting whilst trying to build the solution, yet when i compile each file in the poject they compile fine. its jsut this when i try and build the solution. any idea why i get this?

##### Share on other sites
It looks like you have the declaration for a constructor for the Material class, but no definition. ie:
class Material{public:   Material( );   // declaration!...};// You need thisMaterial::Material( )   // definition!{}

HTH

##### Share on other sites
thats the thing i do have a definition and a decleration
Definition:
class Material : public Resource< Material >
{
}

Decleration:
Material::Material( char *name, char *path ) : Resource< Material >( name, path )
{
}

im not sure if its to do with this though. its the class derived from material:

class GameMaterial : public Material
{
};

Decleration:
GameMaterial::GameMaterial( char *name, char *path ) : Material( name, path )
{
};

is it because i dont have brackets before GameMaterial? not at the pc with the code all on at the moment so cant check.

##### Share on other sites
The linker is looking for the default Material constructor (e.g. one with no arguments). So, apparently you have a reference somewhere in your code to a Material (or Material derivative) that needs the default constructor, perhaps in a copy operation or similar.

##### Share on other sites
but wouldnt that come up when trying to link indiviual files not the whole project?

also how would i fix something like this?

(getting prepared here for tomorrow when i go back into uni and get back on the code)

##### Share on other sites
Having re-read your code it's not either of the first two things I thought it might be.

Something, somewhere, in your code is trying to create a material object using a default constructor that is declared but not defined. That's a certainty as far as I can see. From the snippets you've posted, it's not clear where - so we're going to need to see more code. (If you're away from the PC with all the code on, how have you been able to post the code you have posted, and know you've got it right? If your GameMaterial class did not construct the Material parent class in it's constructor, that'd cause this problem, so are you certain it does, and you've not just posted it here correctly but it's incorrect in the code?)

##### Share on other sites
Quote:
 Original post by AndyUnibut wouldnt that come up when trying to link indiviual files not the whole project?

No, because this is a link-time error, not a compile-time error and individual files don't link, they just produce .obj files. When compiling individual source files, the compiler has no knowledge of (nor does it care) whether you have an actual implementation of a method anywhere. It's the linker that has the job of resolving all of that. So you won't see this problem until you try to link (e.g. when you build the whole project).

##### Share on other sites
Quote:
 Original post by SunTzuHaving re-read your code it's not either of the first two things I thought it might be.Something, somewhere, in your code is trying to create a material object using a default constructor that is declared but not defined. That's a certainty as far as I can see. From the snippets you've posted, it's not clear where - so we're going to need to see more code. (If you're away from the PC with all the code on, how have you been able to post the code you have posted, and know you've got it right? If your GameMaterial class did not construct the Material parent class in it's constructor, that'd cause this problem, so are you certain it does, and you've not just posted it here correctly but it's incorrect in the code?)

i came into uni early to try and fix this, the snippets were from printouts i did in note pad whilst doing the skeleton of the game.

but thanks for your help lads ive fixed it now it was because i had the an extra constructor in their that was a instance of Material() and removing that made the thing work. cheers for the advice

##### Share on other sites

This topic is 3935 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628706
• Total Posts
2984309

• 23
• 10
• 9
• 13
• 13