小编jee*_*ali的帖子

main()的多重定义

嗨伙计们试图使用两个main()并获得此错误多次定义main().我重命名了我的主要功能然后为什么是这个错误,并且首先在这里为我的print()定义.头文件:

#ifndef TOP_H_
#define TOP_H_

#include <stdio.h>
#include <string.h>
#define onemain main
#define twomain main
inline void print();


#endif /* TOP_H_ */
Run Code Online (Sandbox Code Playgroud)

c文件一:

#include "top.h"
void print();
int onemain()
{
    print();
    return 0;
}
void print()
{
printf("hello one");
}
Run Code Online (Sandbox Code Playgroud)

c文件二:

#include "top.h"
void print();
int twomain()
{
    print();
    return 0;
}
void print()
{
printf("hello two");
}
Run Code Online (Sandbox Code Playgroud)

错误快照

c program-entry-point multiple-definition-error

1
推荐指数
1
解决办法
4万
查看次数