小编K71*_*993的帖子

内联函数的多重定义

我已经阅读了一些与此主题相关的帖子,但无法彻底理清我的疑问.这可能是一个非常天真的问题.

我有一个头文件inline.h和两个翻译单元main.cpptran.cpp.

代码详情如下

inline.h

#ifndef __HEADER__
#include <stdio.h>
extern inline int func1(void)
{ return 5; }

static inline int func2(void)
{ return 6; }

inline int func3(void)
{ return 7; }
#endif
Run Code Online (Sandbox Code Playgroud)

main.c中

#define <stdio.h>
#include <inline.h>
int main(int argc, char *argv[])
{
    printf("%d\n",func1());
    printf("%d\n",func2());
    printf("%d\n",func3());
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

tran.cpp

//(note that the functions are not inline here)
#include <stdio.h>
int func1(void)
{ return 500; }

int func2(void)
{ return 600; }

int func3(void) …
Run Code Online (Sandbox Code Playgroud)

c inline

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

标签 统计

c ×1

inline ×1