pullzed at static template member function

J

Jee

Hi,

I want to declare a static template member function inside a non-template class, but MS C compiler always

complains syntax error. I wonder if it is not allowed to do that? I tried SUN Forte compiler, it errored also.

My class is like,

class a{

public:

static template<class T> vector<T> getIntersection(vector<T>&, vector<T>&);

};

Could you point me what's wrong here?
 
S

Simon Saunders

Hi,

I want to declare a static template member function inside a non-template class, but MS C compiler always

complains syntax error. I wonder if it is not allowed to do that? I tried SUN Forte compiler, it errored also.

My class is like,

class a{

public:

static template<class T> vector<T> getIntersection(vector<T>&, vector<T>&);

};

Could you point me what's wrong here?

class a
{
public:
template<class T>
static vector<T> getIntersection(vector<T>&, vector<T>&);
};
 
J

Jee

Simon said:
class a
{
public:
template<class T>
static vector<T> getIntersection(vector<T>&, vector<T>&);
};

I tried this, I got the same error, in MSC the error is
error C2143: syntax error: missing ';' before '<'.

and in Forte the error is
Templates can only declare class and function.


Still puzzled...
 
R

Russell Hanneken

Jee said:
I tried this, I got the same error, in MSC the error is
error C2143: syntax error: missing ';' before '<'.

and in Forte the error is
Templates can only declare class and function.

Did you #include <vector>? Did you type "using namespace std;" or "using
std::vector;"?

This complete example compiles for me with Visual C++ .NET (2002):

#include <vector>

using std::vector;

class a
{
public:
template<class T>
static vector<T> getIntersection(vector<T>&, vector<T>&);
};
 
D

DarkSpy

right code is:
class a{

public:

template<class T> static vector<T> getIntersection(vector<T>&, vector<T>&);

};
 
D

DarkSpy

sorry about my answer with above.

if you got error, please check the MSC's version, maybe it is not
enough modern to compile this code :) or check the STL, please code:
#include <vector>
using namespace std; or using std::vector;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top