I made 3 files in the same directory lec42.cpp
, MohitSinghania.cpp
and
MohitSinghania.h
.
MohitSinghania.h
#ifndef MOHITSINGHANIA_H
#define MOHITSINGHANIA_H
class MohitSinghania
{
public:
MohitSinghania();
void grtQuotation();
};
#endif // MOHITSINGHANIA_H
MohitSinghania.cpp
#include "MohitSinghania.h"
#include<iostream>
using namespace std;
MohitSinghania::MohitSinghania()
{
}
void MohitSinghania::grtQuotation(){
cout<<"Get Up But Don't Give Up!\n";
}
lec42.cpp
#include<iostream>
#include "MohitSinghania.h"
using namespace std;
int main(){
MohitSinghania ms;
ms.grtQuotation();
}
Now when I compile lec42.cpp
in cmd then it shows this error:
G:\code\pracc++>c++ lec42.cpp
C:\Users\mohit\AppData\Local\Temp\ccE5vbeE.o:lec42.cpp:(.text+0x15): undefined reference to `MohitSinghania::MohitSinghania()'
C:\Users\mohit\AppData\Local\Temp\ccE5vbeE.o:lec42.cpp:(.text+0x20): undefined reference to `MohitSinghania::grtQuotation()
link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
the MohitSinghania.cpp is also not compiling
g:\code\pracc++>c++ MohitSinghania.cpp
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../.. /../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
,MohitSinghania.h is compiling with instruction
c++ MohitSinghania.h