单独的类文件程序在C ++中显示错误

时间:2015-09-13 13:38:20

标签: c++ gcc compiler-errors

我在同一目录lec42.cppMohitSinghania.cppMohitSinghania.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();

}

现在,当我在cmd中编译lec42.cpp时,它会显示以下错误:

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

MohitSinghania.cpp也没有编译

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正在编写指令

c++ MohitSinghania.h

0 个答案:

没有答案