Jump to content
  • Advertisement
Sign in to follow this  
jamesleighe

Templates

This topic is 2578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Best explained in code:

I have this.

template<class T>
class OcTreeOptimized
{
public:
template<class T>
class Node
{
Node ();
}
};


But I can't do this!

template<class T>
OcTreeOptimized<T>::Node<T>::Node ()
{
; // do stuff
}


I get the compiler error "error C3860: template argument list following class template name must list parameters in the order used in template parameter list".
Is there any way around this?

Thanks as usual!

Share this post


Link to post
Share on other sites
Advertisement
You can do that like:

template<class T>
class OcTreeOptimized {
public:
template<class U>
class Node {
Node ();
};
};

template <class T>
template <class U>
OcTreeOptimized<T>::Node<U>::Node() {
// stuff
}

Share this post


Link to post
Share on other sites

Best explained in code:

I have this.

template<class T>
class OcTreeOptimized
{
public:
template<class T>
class Node
{
Node ();
}
};


But I can't do this!

template<class T>
OcTreeOptimized<T>::Node<T>::Node ()
{
; // do stuff
}


I get the compiler error "error C3860: template argument list following class template name must list parameters in the order used in template parameter list".
Is there any way around this?

Thanks as usual!



If you want Node to be of type T, then upon creating OcTreeOptimized, the type of T will be known, thus you can simply do this :

template<typename T>
class Foo{
class Bar{
T val;
Bar() : {}
}
};


else you can take SiCrane's suggestion

Share this post


Link to post
Share on other sites
I can't think of a good reason for templating the inner Node class on a *different* type to the outer Octree class. Do you intend for them to be templated on the same type T?

If that is not what you meant, then go with SiCrane's solution, and name the template types two different names.

But if you want them templated on the same type, then you don't need a template declaration at all on the inner class - inner classes of template classes are already templated based on the same template as the surrounding class.

Share this post


Link to post
Share on other sites

I can't think of a good reason for templating the inner Node class on a *different* type to the outer Octree class. Do you intend for them to be templated on the same type T?

If that is not what you meant, then go with SiCrane's solution, and name the template types two different names.

But if you want them templated on the same type, then you don't need a template declaration at all on the inner class - inner classes of template classes are already templated based on the same template as the surrounding class.


This is what I meant, I see what I did wrong now.

Share this post


Link to post
Share on other sites
Follow up question!

This code:


template <class T> void
OcTreeOptimized<T>::FindNodesIntersectingAABox (Vector3D& mins, Vector3D& maxs, Vector<OcTreeOptimized::Node*>& nodes)
{
;
}


Generates "warning C4346: 'OcTreeOptimized<T>::Node' : dependent name is not a type prefix with 'typename' to indicate a type".
It then generates a bunch of syntax errors.

Whats going on here?


(Here is the new declaration in case)


template<class T>
class OcTreeOptimized
{
public:
class Node
{
;
};
};


Thanks!

Share this post


Link to post
Share on other sites

This code:

template <class T> void
OcTreeOptimized<T>::FindNodesIntersectingAABox (Vector3D& mins, Vector3D& maxs, Vector<OcTreeOptimized::Node*>& nodes)
{
;
}

Generates "warning C4346: 'OcTreeOptimized<T>::Node' : dependent name is not a type prefix with 'typename' to indicate a type".


You are using a dependent name (OcTreeOptimized::Node) to refer to a type, and according to the standard the compiler isn't allowed to interpret dependent names as types without an explicit 'typename' declaration. In theory at least, this ought to solve it:

template <class T> void
OcTreeOptimized<T>::FindNodesIntersectingAABox (Vector3D& mins, Vector3D& maxs, Vector<typename OcTreeOptimized::Node *>& nodes)
{
}

Note that the first response from google for that "warning C4346" answers your question in some detail.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!