In C++ I am not able to link source code file and its header files. I am keeping both files in same folder/directory. Also I am using another class which imports header file and it is the startng point of the application but when I am compiling I am getting following error message:
C:\Users\SONY-V~1\AppData\Local\Temp\ccetXYNN.o Marksheet_Test.cpp:(.text+0x74): undefined reference to `Marksheet::Marksheet(std::string, std::string)'
C:\Users\SONY-V~1\AppData\Local\Temp\ccetXYNN.o Marksheet_Test.cpp:(.text+0xa9): undefined reference to `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
is a cpp file of which header I am making and Marksheet_Test
is starting point of the application.
Can somebody help me solving this problem?
Code is as follows: This is code for Marksheet_Test
#include "Marksheet.h"
using namespace std;
int main()
{
Marksheet obj1("Pransanjeet Majumder","IT 114 Objject Oriented programming");
obj1.dispmessage();
}
Following code is 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()
{
return coursename;
}
string Marksheet::getinstname()
{
return instname;
}
void Marksheet::dispmessage()
{
cout<<"Welcome to the "<<coursename<<"\n";
cout<<"This course is offered by Prof."<<instname<<endl;
}
};
Following code is 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 am using DEVC++ compiler for compiling the code