C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Template problem

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Richard Hayden
Guest





PostPosted: Sun Jun 27, 2004 11:22 pm    Post subject: Template problem Reply with 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<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





PostPosted: Sun Jun 27, 2004 11:43 pm    Post subject: Re: Template problem Reply with quote



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





PostPosted: Sun Jun 27, 2004 11:43 pm    Post subject: Re: Template problem Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.