[英]Error: Function not declared in this scope. Help?
这是我的代码(的一部分):
...
Node<char*>* nodes[count2];//array of pointers to last level
nodes[0] = f1.rootPtr;
processInput(input, f1.rootPtr, nodes, 0, count2);
//I get an error that says this function is not declared in this scope.
return input;
}
void processInput(istream& input, Node<char*>* node, Node<char*>** nodeArray,
int level, int& count)
{
//variables
Node<char*>* aNode = new Node<char*>();
char charArray[150];
...
当我运行程序时,我得到以下信息:
Forest.cpp: In function 'std::istream& operator>>(std::istream&, Forest<char*>&)':
Forest.cpp:93:53: error: 'processInput' was not declared in this scope
make[2]: *** [build/Debug/MinGW-Windows/Forest.o] Error 1
make[1]: *** [.build-conf] Error 2
这是头文件的一部分:
template<typename NODETYPE> class Forest{
/*
* builds a forests consisting of the first and second forest reference
*/
template<NODETYPE>
friend Forest& operator+(Forest<NODETYPE>& f1, Forest<NODETYPE>& f2);
/*
* insert into the output stream a preorder traversal of the input forest
*/
template<NODETYPE>
friend ostream& operator<<(ostream& ostr, const Forest<NODETYPE>& f1);
/*
* extracts a forest from the input stream and builds it for the forest argument variable name
*/
//template<NODETYPE>
friend istream& operator>>(istream& file, Forest<char*>& f1);
/*
*Used with istream to go through input
*/
//template<NODETYPE>
void processInput(istream& input, Node<char*>* nodeBefore, Node<char*> ** nodeArray,
int levelBefore, int& count);
public:
Forest(){
..
我究竟做错了什么? 为什么会出现该错误。 有什么建议吗?
谢谢!
编辑:
我尝试了您所说的内容,但仍然无法正常工作。 我虽然使用模板,但是也许这就是我的问题所在?
标头:
模板//我应该保持这个?? 当我将其取出时,它也不起作用。朋友istream&运算符>>(istream&文件,Forest&f1);
私人的:
void processInput(istream&input,Node * node,Node ** nodeArray,int level,int&count);复制代码
.cpp文件:
模板istream&operator >>(istream&input,Forest&f1){//代码... processInput(input,f1.rootPtr,nodes,0,count2); //错误:无法解析标识符processInput}
/ ** *处理输入/ void Forest :: processInput(istream&input,Node node,Node ** nodeArray,int level,int&count){//代码
再次感谢。
您需要在类函数的前面加上类名,您目前正在这样做吗? 如果不是,则编译器认为它们是自由函数。
例如,
void processInput(istream& input, Node<char*>* node, Node<char*>** nodeArray,
int level, int& count) {
// ...code...
}
应该
void Forest::processInput(istream& input, Node<char*>* node, Node<char*>** nodeArray,
int level, int& count) {
// ...code...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.