请教一下关于类文件编译的问题
我写了3个文件,一个类声明,一个写类的接口,还有一个使用类的程序,为什么
编译借口文件的时候总提示 [Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status
谢谢啦
我写了3个文件,一个类声明,一个写类的接口,还有一个使用类的程序,为什么
编译借口文件的时候总提示 [Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status
谢谢啦
If that happens, try the following (without using any IDE).
The baisc idea is still:
edit sourc code --> compile --> link --> run
Step 1: edit source code
prepare 3 files as follows (using any text editor):
class.h
class A
{
public:
A(int i_=0);
void print() const;
private:
int i;
};
class.cpp
#include \"class.h\"
#include <iostream>A::A(int i_) : i(i_)
{}
void A::print() const
{
std::cout<<i<<std::endl;
}
main.cpp
#include <iostream>
#include \"class.h\"
using namespace std;
int main()
{
A a(3);
a.print();return 0;
}
Step 2: compile and link
Open a command prompt window, and run
C:\Dev-Cpp\bin\g++ main.cpp class.cpp
Step 3: run
run a.exe