【发布时间】:2014-05-26 02:04:46
【问题描述】:
晚上好,
你们中的一些人可能会认为这是一个愚蠢的问题。但是我已经开始学习 C++,一切都很顺利,直到我遇到了这个困扰我好几天的错误。到目前为止,我已经对网络进行了一些研究并修复了所有问题。
问题是,当我尝试包含我制作的新头文件时,编译器无法识别该文件的内容。我正在使用 Dev-C++ 编译器。
当我尝试编译时出现以下错误:main.cpp line 8 error: `test123' undeclared (first use this function)
我有一个名为 001 的文件夹,其中还有另一个名为 src 的文件夹(我在其中存储我的 .h 文件),以及 main.cpp 和 new.cpp 。
这是main.cpp的代码:
#include <iostream>
#include "src/functions.h"
using namespace std;
int main(){
test123(5,'Test String');
//close on enter keystroke
cin.clear();
cin.ignore(255,'\n');
cin.get();
return 0;
}
这是functions.h中的代码:
#ifndef FUNCTIONS_H_INCLUDED
#define FUNCTIONS_H_INCLUDED
string test123(int i,string inputStr);
#endif
这是functions.cpp中的代码:
#include "src/functions.h"
string test123(int n, inputStr){
for(int i=0;i<=n;i++){
cout << "\n\t"+inputStr <<endl;
}
}
【问题讨论】:
-
我得到一个错误:`test123' undeclared (首先使用这个函数)
-
那是你的真实代码吗?我看不出functions.cpp是如何编译的。