0

[repost} C++ Code Block

Can someone help me what am I doing wrong here? ---------------------------------------------------------------------------------------------------- main cpp ------------------- #include <iostream> #include "MeineClassfirst.h" using namespace std; int main(){ MeineClassfirst obj; obj.myPrint(); cout << "Hello world!" << endl; return 0; } -------------------------------- MeineClassfirst.h ------------------------------- #ifndef MEINECLASSFIRST_H #define MEINECLASSFIRST_H #include <iostream> class MeineClassfirst { public: MeineClassfirst(); void myPrint(); ~MeineClassfirst(); protected: private: }; #endif // MEINECLASSFIRST_H ------------------------------------- MeineClassfirst.cpp ------------------------------------ #include "MeineClassfirst.h" #include <iostream> using namespace std; MeineClassfirst::MeineClassfirst() { cout<<"Constructor"<<endl; //ctor } void MeineClassfirst::myPrint(){ cout<<"Hello"<<endl; } MeineClassfirst::~MeineClassfirst() { cout<<"Destructor"<<endl; } -------------------------------------------------- After the run build messages shows ----------------------------- // Line// 7 undefined reference to 'MeineClassfirst::MeineClassfirst()' //Line// 8 undefined reference to 'MeinClassfirst::myPrint()' //Line// 7 undefined reference to 'MeineClassfirst::~MeineClassfirst()' //Line// 7 undefined reference to 'MeineClassfirst::~MeineClassfirst()' --------------------------------------- Thank you!

7th Aug 2020, 5:19 AM
Bbrbk
4 Respostas
+ 2
Bbrbk Your error stems from the fact that the linker cannot find the 4 functions you've listed above. You can resolve this issue in two ways: 1.Ensure that you compile and run your code in code blocks as a project.That way,the IDE will pass the necessary .o(object) files to the linker. 2.add #include "MeineClassfirst.cpp" To your main.cpp file.(Though I don't recommend using this method since it kind of beats the purpose of separating the interface from the implementation.)
7th Aug 2020, 8:08 AM
Anthony Maina
Anthony Maina - avatar
0
What's your error?
7th Aug 2020, 7:02 AM
The future is now thanks to science
The future is now thanks to science - avatar
0
After the run build messages shows ----------------------------- // Line// 7 undefined reference to 'MeineClassfirst::MeineClassfirst()' //Line// 8 undefined reference to 'MeinClassfirst::myPrint()' //Line// 7 undefined reference to 'MeineClassfirst::~MeineClassfirst()' //Line// 7 undefined reference to 'MeineClassfirst::~MeineClassfirst()' --------------------------------------- Thank you!
7th Aug 2020, 7:08 AM
Bbrbk