Original Post
I've got a fun little compiler error and have absolutely no idea how to fix it. I have a class called VariableLabel detailed below. Note that the sf namespace refers to SFML.
If I comment out all the functions, everything works. But if I even decide to include the definition of the constructor in the .h file (while still leaving its implementation in the .cpp file commented out), the following error is produced.
The compiler is telling me 1>Simulation.obj : error LNK2019: unresolved external symbol "public: __thiscall VariableLabel::VariableLabel(void)" (??0VariableLabel@@QAE@XZ) referenced in function "public: __thiscall Simulation::Simulation(class std::basic_string,class std::allocator >,int,int,int)" (??0Simulation@@QAE@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@HHH@Z)
Instances of VariableLabel are declared as private in my class called Simulation.
On another note, I have another random question regarding my implementation of the constructor. If I declare an instance of VariableLabel before called the static function "static bool Initialize(const std::string& ImageFile)", would I receive an error? I ask this because the constructor would otherwise be accessing the variable image when it is has not been initialized.
Thank you.
-Nick
////////////VariableLabel.h#include "headers.h"#pragma onceclass VariableLabel{public: VariableLabel(); static bool Initialize(const std::string& ImageFile);private: static sf::Image image; // Each sprite object shares this single image sf::Sprite Sprite; // But there is one sprite per variable label double value;};////////////VariableLabel.cpp#include "VariableLabel.h"VariableLabel::VariableLabel(){ Sprite.SetImage(image); // Every sprite uses the same image}bool VariableLabel::Initialize(const std::string& ImageFile){ return image.LoadFromFile(ImageFile);}If I comment out all the functions, everything works. But if I even decide to include the definition of the constructor in the .h file (while still leaving its implementation in the .cpp file commented out), the following error is produced.
The compiler is telling me 1>Simulation.obj : error LNK2019: unresolved external symbol "public: __thiscall VariableLabel::VariableLabel(void)" (??0VariableLabel@@QAE@XZ) referenced in function "public: __thiscall Simulation::Simulation(class std::basic_string
Instances of VariableLabel are declared as private in my class called Simulation.
On another note, I have another random question regarding my implementation of the constructor. If I declare an instance of VariableLabel before called the static function "static bool Initialize(const std::string& ImageFile)", would I receive an error? I ask this because the constructor would otherwise be accessing the variable image when it is has not been initialized.
Thank you.
-Nick