开发者

Error: Function not declared in this scope. Help?

开发者 https://www.devze.com 2023-02-22 01:47 出处:网络
Here is (part of) my code: ... Node<char*>* nodes[count2];//array of pointers to last level nodes[0] = f1.rootPtr;

Here is (part of) my code:

...

 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];
...

When I run the program I get this:

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

Here is part of the header file:

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<NODET开发者_如何学编程YPE>& 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(){

..

What am I doing wrong? Why do I get that error. Any advice?

Thanks!

EDIT:

I tried what you said, but it still isn't working. I'm using templates though, so maybe that's where my problem lies?

Header:

template //SHOULD I KEEP THIS?? When I take it out it also doesn't work friend istream& operator>>(istream& file, Forest& f1);

private:

void processInput(istream& input, Node* node, Node ** nodeArray, int level, int& count);

.cpp file:

template istream& operator>> (istream &input, Forest& f1){ //code ... processInput(input, f1.rootPtr, nodes, 0, count2); //ERROR: Unable to resolve identifier processInput }

/** * Processes the input / void Forest::processInput(istream& input, Node node, Node** nodeArray, int level, int& count){ //code

Thanks again.


You need to prefix your class functions with the name of their class, do you do that currently? If not, the compiler thinks that they are free functions.

For example,

void processInput(istream& input, Node<char*>* node, Node<char*>** nodeArray,
    int level, int& count) {
    // ...code...
}

should be

void Forest::processInput(istream& input, Node<char*>* node, Node<char*>** nodeArray,
    int level, int& count) {
    // ...code...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消