在同一名称空间中使用函数查询函数。我该如何调用该功能?它似乎继续给我错误。
// in the .h files
namespace helper{
void helper1();
void helper2();
}
// in the cpp files
namespace helper{
void helper1() {
// blah blah blah
}
void helper2() {
// blah blah blah
helper1(); // return some results from helper1
}
}
上面的代码给出了错误结果,说它无法找到helper1
函数。有什么我做错了吗?
感谢您的帮助!
答案 0 :(得分:0)
你确定你问的是正确的问题吗?这就是我所拥有的,它运作良好:
// this is helper.cpp
#include<iostream>
#include "helper.hpp"
namespace helper{
void helper1() {
std::cout<<"calling helper 1"<<std::endl;
}
void helper2() {
std::cout<<"calling helper 2"<<std::endl;
helper1();
}
}
int main() {
helper::helper2();
return 0;
}
和头文件
//this is helper.hpp
namespace helper{
void helper1();
void helper2();
}
使用
编译g++ helper.cpp -ansi -Wall -Wextra -pedantic
不返回任何警告和产量
$ ./a.out
calling helper 2
calling helper 1