| Topic: |
DEVELOP > c-Plus-Plus |
| User: |
"Jee" |
| Date: |
10 Oct 2003 03:49:15 PM |
| Object: |
Does Visual C++ support member function template? |
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.
.
|
|
| User: "David B. Held" |
|
| Title: Re: Does Visual C++ support member function template? |
11 Oct 2003 01:21:46 AM |
|
|
"Jee" <jee@hotmail.com> wrote in message
news:3F871B4B.A55BA19C@hotmail.com...
[...]
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
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003
.
|
|
|
|
| User: "Moonlit" |
|
| Title: Re: Does Visual C++ support member function template? |
10 Oct 2003 05:53:26 PM |
|
|
Hi,
"Jee" <jee@hotmail.com> wrote in message
news:3F871B4B.A55BA19C@hotmail.com...
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.
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.
.
|
|
|
| User: "Moonlit" |
|
| Title: Re: Does Visual C++ support member function template? |
10 Oct 2003 06:10:52 PM |
|
|
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
.
|
|
|
|
|

|
Related Articles |
|
|