|
-
May 1st, 2004, 06:44 AM
#1
Help with templates in C++
Why doesn't this code work???
Code:
template<class t>
t sum( t a, t b )
{
return a + b;
}
template<class t>
class c_x {
public:
t a, b, c;
void sum()
{
c = sum( a, b );
}
};
void main()
{
c_x<int> x;
x.a = 10;
x.b = 20;
x.sum();
}
Error
C2660: 'c_x<t>::sum' : function does not take 2 arguments
with
[
t=int
]
-
May 1st, 2004, 07:12 AM
#2
Code:
template<class t>
t sum( t a, t b )
{
return a + b;
}
Code:
void sum()
{
c = sum( a, b );
}
in case you don't get it, what does:
sum(a,b) resolve to in class c_x...
Last edited by Mick; May 1st, 2004 at 07:23 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|