facing error in linking codes in c++ -



facing error in linking codes in c++ -

this question has reply here:

what undefined reference/unresolved external symbol error , how prepare it? 23 answers

in c++ not able link source code file , header files. keeping both files in same folder/directory. using class imports header file , startng point of application when compiling getting next error message:

c:\users\sony-v~1\appdata\local\temp\ccetxynn.o marksheet_test.cpp:(.text+0x74): undefined reference `marksheet::marksheet(std::string, std::string)'

c:\users\sony-v~1\appdata\local\temp\ccetxynn.o marksheet_test.cpp:(.text+0xa9): undefined reference `marksheet::dispmessage()'

e:\education\dev-cpp\mingw32\mingw32\bin\ld.exe c:\users\sony-v~1\appdata\local\temp\ccetxynn.o: bad reloc address 0x13 in section `.text$_zn9marksheetd1ev[__zn9marksheetd1ev]'

e:\education\dev-cpp\mingw32\mingw32\bin\ld.exe final link failed: invalid operation

e:\education\c++ programming\collect2.exe [error] ld returned 1 exit status

here marksheet cpp file of header making , marksheet_test starting point of application.

can help me solving problem?

code follows: code marksheet_test

#include "marksheet.h" using namespace std; int main() { marksheet obj1("pransanjeet majumder","it 114 objject oriented programming"); obj1.dispmessage(); }

following code of marksheet.cpp

#include<iostream> #include "marksheet.h" using namespace std; class marksheet{ marksheet::marksheet(string cname,string instname){ setcoursename(cname); setinstname(instname); } void marksheet::setcoursename(string cname) { coursename=cname; } void marksheet::setinstname(string insname){ instname=insname; } string marksheet::getcoursename() { homecoming coursename; } string marksheet::getinstname() { homecoming instname; } void marksheet::dispmessage() { cout<<"welcome "<<coursename<<"\n"; cout<<"this course of study offered prof."<<instname<<endl; } };

following code of marksheet.h header file

#include<string> using namespace std; class marksheet { public: marksheet(string,string); void setcoursename(string); string getcoursename(); void dispmessage(); void setinstname(string); string getinstname(); private: string coursename; string instname; };

i using devc++ compiler compiling code

you have class marksheet around implementations unnecessary. alter marksheet.cpp to:

#include<iostream> #include "marksheet.h" using namespace std; marksheet::marksheet(string cname,string instname) { setcoursename(cname); setinstname(instname); } void marksheet::setcoursename(string cname) { coursename=cname; } void marksheet::setinstname(string insname) { instname=insname; } string marksheet::getcoursename() { homecoming coursename; } string marksheet::getinstname() { homecoming instname; } void marksheet::dispmessage() { cout<<"welcome "<<coursename<<"\n"; cout<<"this course of study offered prof."<<instname<<endl; }

note there no class in definition file.

what doing declaring new class called marksheet , attempted define it's own members without declaring them. should not set using declarations in header files class includes them have utilize same declaration. can lead hard find conflicts @ compile time.

c++

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -