相关疑难解决方法(0)

C/C++标题和实现文件:它们如何工作?

可能是一个愚蠢的问题,但我现在在网上和网上搜索了很长一段时间并且无法得出一个明确的答案(我的尽职调查谷歌搜索).

所以我是编程的新手......我的问题是,主函数如何知道不同文件中的函数定义(实现)?

恩.说我有3个文件

  • main.cpp中
  • myfunction.cpp
  • myfunction.hpp

//main.cpp

#include "myfunction.hpp"
int main() {
  int A = myfunction( 12 );
  ...
}
Run Code Online (Sandbox Code Playgroud)

-

//myfunction.cpp

#include "myfunction.hpp"
int myfunction( int x ) {
  return x * x;
}
Run Code Online (Sandbox Code Playgroud)

-

//myfunction.hpp

int myfunction( int x );
Run Code Online (Sandbox Code Playgroud)

-

我得到预处理器如何包含头代码,但是头和主函数如何知道函数定义是否存在,更不用说它了?

如果不清楚或者我对这里的新事物有很大误解,我会道歉

c++ compilation header-files

40
推荐指数
3
解决办法
2万
查看次数

没有实现文件时包括头文件?

我正在查看 ncmpcpp 的源代码,我看到了这个。

#include <mpd/client.h>
Run Code Online (Sandbox Code Playgroud)

在该文件中是由 ncmpcpp 使用的函数。但这些只是标题。cpp 文件不是也必须存在于某处吗?我在同一目录中找不到它们。他们在哪里?

另外,当包含的内容被 < 和 > 包围时,我怎么知道去哪里看?

c++ compilation header-files

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

标签 统计

c++ ×2

compilation ×2

header-files ×2