 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Richard Hayden Guest
|
Posted: Sun Jun 27, 2004 11:22 pm Post subject: Template problem |
|
|
Hi,
I'm just learning about C++ templates and can't understand why the
following code is not working as expected:
/*************************************
#include <iostream>
template<class C>C func(C c) {
return c;
}
int main(int argc, char** argv) {
std::cout << afunc(23); // OUTPUTS '5' INSTEAD OF '23'
}
/*************************************
I'd be very grateful if someone could explain to me why this code is not
working as expected and outputting '5' instead of '23'.
Thanks,
--
Richard Hayden
http://www.dx-dev.com
|
|
| Back to top |
|
 |
Ali Cehreli Guest
|
Posted: Sun Jun 27, 2004 11:43 pm Post subject: Re: Template problem |
|
|
On Sun, 27 Jun 2004 23:22:52 +0000, Richard Hayden wrote:
| Quote: | Hi,
I'm just learning about C++ templates and can't understand why the
following code is not working as expected:
/*************************************
#include <iostream
template
return c;
}
int main(int argc, char** argv) {
std::cout << afunc(23); // OUTPUTS '5' INSTEAD OF '23'
|
This is not 'func' but 'afunc'.
| Quote: | }
/*************************************
I'd be very grateful if someone could explain to me why this code is not
working as expected and outputting '5' instead of '23'.
Thanks,
|
In the part of your code that you did not post, there is a function called
afunc that outputs 5.
Ali
|
|
| Back to top |
|
 |
Russell Hanneken Guest
|
Posted: Sun Jun 27, 2004 11:43 pm Post subject: Re: Template problem |
|
|
Richard Hayden wrote:
| Quote: |
I'm just learning about C++ templates and can't understand why the
following code is not working as expected:
/*************************************
#include <iostream
template
return c;
}
int main(int argc, char** argv) {
std::cout << afunc(23); // OUTPUTS '5' INSTEAD OF '23'
}
/*************************************
I'd be very grateful if someone could explain to me why this code is not
working as expected and outputting '5' instead of '23'.
|
It's hard to say without seeing the definition of afunc. Or did you
mean to call func rather than afunc?
--
Russell Hanneken
[email]eunaarxra (AT) cbobk (DOT) pbz[/email]
Use ROT13 to decode my email address.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|