注册 登录
编程论坛 C++教室

请教一下关于类文件编译的问题

flyingni 发布于 2007-09-18 11:22, 557 次点击

我写了3个文件,一个类声明,一个写类的接口,还有一个使用类的程序,为什么
编译借口文件的时候总提示 [Linker error] undefined reference to `WinMain@16'
ld returned 1 exit status

谢谢啦

8 回复
#2
HJin2007-09-18 11:33
are you writing a GUI program or a console program?

Console program does not call WinMain(), it calls main().
#3
flyingni2007-09-18 12:20
回复:(flyingni)请教一下关于类文件编译的问题
就是在devc++里面打开source文件然后写的啊,不理解你说的那2个术语。。。
#4
HJin2007-09-18 12:45
回复:(flyingni)回复:(flyingni)请教一下关于类...

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

#5
flyingni2007-09-18 15:00
回复:(flyingni)回复:(flyingni)请教一下关于类...

不好意思,第2步里面输入的命令和自己文件存放的位置有关吗?麻烦能说清楚些不,我是新手,好多不明白的

#6
HJin2007-09-18 15:20
回复:(flyingni)回复:(flyingni)回复:(flying...
see picture.
只有本站会员才能查看附件,请 登录

[此贴子已经被作者于2007-9-18 15:22:17编辑过]

#7
flyingni2007-09-18 16:57
回复:(flyingni)回复:(flyingni)回复:(flying...
问题解决啦,太谢谢了!关于这方面的东西有教材之类的吗?
#8
HJin2007-09-18 19:16
Are you self-learning programming?

If you have a teacher, he should have taught you this "climb" step before the "walk" step (using IDE).
#9
flyingni2007-09-19 14:31
回复:(flyingni)回复:(flyingni)回复:(flying...
我是一个人课余时间在学的,有什么好的方法吗
1