0

I have a Node class in another class which is under private in the Structure class which is the main class I am working with. I am then in another .cpp file which implementing the functions that are in the structure.h file which contains the Structure class and the Node class nested inside the Structure class under private.

How do I access that Node class when creating a return type of Node*. I have been messing around with it for awhile and nothing will work. It allows me to return an int, bool, double, but not a Node*.

"Structure.h"
template <class T> 
class Structure
{
    public:
        // Structure functions();
    private:

    class Node
{
    public::
        // Node functions and variables;
}
    // Structure functions_private();
}
halfer
  • 19,824
  • 17
  • 99
  • 186
  • I also meant to add that I want in the .cpp file a function to look like this: Node* Structure::function(x,y); – user3596926 May 02 '14 at 16:33
  • Outside the class definition, you have to use the fully qualified type name, `typename Structure::Node`. And you probably can't put that function in a source file: http://stackoverflow.com/questions/495021. – Mike Seymour May 02 '14 at 16:35
  • So how would i go about returning a Structure::Node in a source file? – user3596926 May 02 '14 at 16:36
  • If it's a template, then you probably wouldn't, because it would probably have to be in a header. See my answer for how to do it in either case. – Mike Seymour May 02 '14 at 16:39
  • Since you are new to this site, you should search it first for existing questions, like this one. – Thomas Matthews May 02 '14 at 19:15

2 Answers2

1

Do you mean something like:

template< class T >
typename Structure<T>::Node* Structure<T>::MyMemberFunction()
{
    return new Node();
}

As an example.

Also you'll need to put this in your header file not in the source.

qeadz
  • 1,476
  • 1
  • 9
  • 17
1

Within the class definition, you can simply refer to the type as Node.

Outside, you need the qualified name, along with typename if it depends on a template parameter:

Structure<int>::Node * some_function();  // not dependent, no typename

template <typename T>
typename Structure<T>::Node * some_template(); // dependent, needs typename
Mike Seymour
  • 249,747
  • 28
  • 448
  • 644