TransWikia.com

C++ nested class inside of a templated class

Stack Overflow Asked by Dentiny on December 16, 2021

I have a template class LinkedList, which depends on the template type T.
Inside of the class LinkedList, there’s a nested class Node, which also depends T.
I try to implement Node class in a seperate .h/.cc files, but failed somehow.

The LinkedList.h is:

template <typename T>
class LinkedList {
public:
    class Node;

private:
    std::shared_ptr<Node> head;
    std::shared_ptr<Node> tail;
};

BaseNode.h is:

template<typename kOwner>
class BaseNode {
    // some definition
}

Node.h is:

template <typename T>
class LinkedList<T>::Node : public BaseNode<LinkedList<T>>{
private:
    T data;
    std::shared_ptr<Node> next;
    void Start();
}

Node.cc is:

template<typename T>
void LinkedList<T>::Node(MetadataManager *metadata_manager) :
    BaseNode(metadata_manager){}

template<typename T>
void ListedList<T>::Node::Start() {
    // do some operations
}

The error I got is

error: member initializer 'BaseNode' does not name a non-static data member or base class
        BaseNode(metadata_manager) {

Can someone tell me how to implement it please?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP