我想知道当同时包含两个文件时,如何从另一个文件中调用与另一个文件中的函数同名的函数。例:
main.cpp
#include "a.h"
#include "b.h"
using namespace std;
int main()
{
start();
return 0;
}
啊
#ifndef _A_H
#define _A_H
#pragma once
int start();
#endif
cpp文件
#include "stdafx.h"
using namespace std;
int start()
{
//code here
return 0;
}
h
#ifndef _B_H
#define _Win32_H
#pragma once
int start();
#endif
cpp文件
#include "stdafx.h"
using namespace std;
int start()
{
//code here
return 0;
}
开始(); 在main.cpp中将使用start(); 从啊,但我希望它使用start(); from bh我该如何选择start(); 在bh?
假设功能在相应的.cpp
文件中定义,即在中定义了a.cpp
一个,在中定义了一个b.cpp
,那么这不会发生。一旦尝试链接代码,您将得到start()
两次定义的错误。因此,您不必推理如何调用其中之一。除非两个函数相同(即在同一个cpp文件中定义),否则该代码将不会链接。如果是这种情况,那么调用哪一个都没有关系(因为只有一个)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句