tags:

views:

52

answers:

2
// InternalTemplate.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

template<class T>
struct LeftSide
{
 static void insert(T*& newLink, T*& parent)
 {
  parent->getLeft() = newLink;
  newLink->parent = newLink;
 }
};

template<class T>
struct Link
{
 T* parent_;
 T* left_;
 T* right_;
 T*& getParent()const
 {
  return parent_;
 }
 template<class Side>
 void plugIn(Link<T>*& newLink);


};

template<class T>
template<class Side>
void Link<T>::plugIn(Link<T>*& newLink)//<<-----why can't I type  
//void Link<T>::plugIn<Side>(Link<T>*& newLink)<---<Side> next to plugIn


{
 Side::insert(newLink,this);
}

int _tmain(int argc, _TCHAR* argv[])
{
 return 0;
}

I find it strange that I have to specify parameter for class but cannot specify parameter for fnc. Is there any reason why?

+1  A: 

$14/2 -

A template-declaration can appear only as a namespace scope or class scope declaration. In a function template declaration, the last component of the declarator-id shall be a template-name or operator-functionid (i.e., not a template-id). [ Note: in a class template declaration, if the class name is a simple-template-id, the declaration declares a class template partial specialization (14.5.5). —end note ]"

The standard forbids such a syntax explicitly. Refer this for more idea about template id / template name

Chubsdad
@Chubsdad so basically there isn't ortogonal syntax preserved (by decision) am I right?
There is nothing we can do
@There is nothing we can do: Yes, There is nothing we can do :)
Chubsdad
@Chubsdad : Yes I think the quote in your post is relevant in this context. `void Link<Side>::plugIn<Side>` compiles on MSVC++[only]. Deleted my answer for it was incorrect.
Prasoon Saurav
A: 

You need to specialize on the Link struct in order to define it's template member function.

template<>
template<class Side>
void Link<int>::plugIn(Link<int>*& newLink)
{
 Side::insert(newLink,this);
}

Gotta be honest, this makes my brain explode a little.

John Dibling