如何从另一个文件中调用与另一个文件中同名的函数(当两者都包含时)
C++ How to call a function from another file with the same name as a function in another file when both are included?
我想知道如何从另一个文件中调用与另一个文件中函数同名的函数,当两者都包含时。例子:
main.cpp
#include "a.h"
#include "b.h"
using namespace std;
int main()
{
start();
return 0;
}
a.h
#ifndef _A_H
#define _A_H
#pragma once
int start();
#endif
a.cpp
#include "stdafx.h"
using namespace std;
int start()
{
//code here
return 0;
}
b.h
#ifndef _B_H
#define _Win32_H
#pragma once
int start();
#endif
b.cpp
#include "stdafx.h"
using namespace std;
int start()
{
//code here
return 0;
}
start ();在main.cpp中将使用start();from a.h,但我想使用start();从b.h如何选择start();在b.h吗?
假设函数在各自的.cpp
文件中定义,即一个在a.cpp
中定义,一个在b.cpp
中定义,则不可能发生这种情况。一旦您尝试链接您的代码,您将得到start()
被定义两次的错误。因此,您不必考虑如何调用其中一个;除非两个函数是相同的(即在相同的CPP文件中定义),否则代码将不会链接。如果是这种情况,那么调用哪个都无关紧要(因为只有一个)。
相关文章:
- 输入到文件并输出到另一个文件,并将流文件传递给函数
- 如何从另一个文件继承私有成员变量和公共函数
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 如何在 Gnuplot 中分别绘制 2 个文件数据?我有一个文件"sin.txt",另一个文件"cos.txt",我想将它们分别绘制在一个图表上
- 如何在安卓工作室中将c ++头文件从一个文件夹导入到另一个文件夹?
- 使用 scope 运算符 (::) 引用另一个文件中的类
- JNI,使用两个 .so 文件时出错,其中一个文件需要另一个文件
- 为什么我不能从同一目录中的另一个文件中 #include 我的类?
- 在 c++ 中打开文件、删除标点符号并追加到另一个文件中
- C++ 如何将两个 makefile 对象目标规则(位于另一个文件夹中)合并到一个目标/规则中?
- 是否可以将子进程的 stdout 重定向到父进程中的另一个文件?
- 如何在标准c ++中流式传输/读取二进制文件的中间部分并写入另一个文件?
- 如何从另一个文件调用类构造函数?
- 包含来自另一个文件的函数会导致范围错误(openFoam)
- 从类中的另一个文件请求函数不起作用
- 从文件中读取成绩并将平均值输出到另一个文件C++
- 包括来自另一个文件的运算符重载
- C++-更改另一个文件的ASM指令
- 如何让 + 重载在另一个文件C++中被识别?
- 引用另一个文件夹中的.dll