简体   繁体   中英

Returning a class member struct with a templated class

I'm trying to create a function that returns a class-defined struct from a templated class. g++ give the error message error: expected constructor, destructor, or type conversion before '*' token . Here is the relevant code:

From BSTDict.cpp:

Node*& BSTDict<T, Compare>::add_helper(Node*& r, T key) { ... }

From BSTDict.hpp:

struct Node {
    T key;
    T data;
    Node* left;
    Node* right;
};

...

Node*& add_helper(Node*& r, T key);

I've done a lot of testing and I think the problem lies with Node (regardless of the reference and pointer). I've tried BSTDict<T, Compare>::Node*& BSTDict<T, Compare>::add_helper(Node*& r, T key) { ... } too. Any help would be appreciated. Thanks.

Edit: Here are BSTDict.hpp and BSTDict.cpp . They are part of a larger program.

template <typename T, typename Compare>
    typename BSTDict<T, Compare>::Node*& 
    BSTDict<T, Compare>::add_helper(Node*& r, T key) 
    { 
       // ... 
    }

I'm not sure about /*typename*/ being required there. I'd have to see more of your code (I had to make up the template<> qualifiers msyefl already :))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM