Does Visual C++ support member function template?

J

Jee

Hi,
Does Visual C++ support member function template? I have the
following code which can not get through VC6
compiler.

In header,
class myclass{
public:
template<class T>
static std::vector<T> getIntersection(std::vector<T>& ,
std::vector<T>& );
};

In Cpp file,
template<class T>
vector<T> myclass::getIntersection(vector<T>& v1, vector<T>&
v2){
vector<T> v;
vector<T>::iterator itr1;

if (v1.size() == 0){
return v;
}

......
return v;
}

This code passes SUN Forte compiler, but VC6 complains on this line,

if (v1.size() == 0){

as " error C2228: left of '.size' must have class/struct/union
type".

Do you know what's wrong here?

Thanks a lot.
 
M

Moonlit

Hi,


Jee said:
Hi,
Does Visual C++ support member function template? I have the Yes, VC6 and later in any case
following code which can not get through VC6
compiler.

In header,
class myclass{
public:
template<class T>
static std::vector<T> getIntersection(std::vector<T>& ,
std::vector<T>& );
};

In Cpp file,
template<class T>
vector<T> myclass::getIntersection(vector<T>& v1, vector<T>&
v2){
vector<T> v;
vector<T>::iterator itr1;

if (v1.size() == 0){
return v;
}

......
return v;
}
Try moving the template function body to the header might help. I am not
sure how the compiler is going to generate code if a part is in the cpp
file. How does it know what it should generate if you fill in a certain
type?


Regards, Ron AF Greve.
 
M

Moonlit

Hi,

Don't think my reply was very clear. What I meant was that if you include
the header from another cpp file (not the one with the template body) how
would it know what the body should look like.

Regards
 
D

David B. Held

Jee said:
[...]
Does Visual C++ support member function template? I
have the following code which can not get through VC6
compiler.
[...]

It has limited and flaky member template function support.
Try asking in a Microsoft newsgroup.

Dave
 

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

No members online now.

Forum statistics

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

Latest Threads

Top