Click here to Skip to main content
15,899,679 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC Slider Direction Pin
ttthearty24-May-06 21:10
ttthearty24-May-06 21:10 
GeneralRe: MFC Slider Direction Pin
_AnsHUMAN_ 24-May-06 21:53
_AnsHUMAN_ 24-May-06 21:53 
GeneralRe: MFC Slider Direction [modified] Pin
_AnsHUMAN_ 24-May-06 21:58
_AnsHUMAN_ 24-May-06 21:58 
GeneralRe: MFC Slider Direction [modified] Pin
ttthearty24-May-06 22:03
ttthearty24-May-06 22:03 
GeneralRe: MFC Slider Direction [modified] Pin
_AnsHUMAN_ 24-May-06 22:08
_AnsHUMAN_ 24-May-06 22:08 
AnswerRe: MFC Slider Direction Pin
Hamid_RT24-May-06 21:45
Hamid_RT24-May-06 21:45 
Questiontemplates Pin
vivek.s.vivek24-May-06 20:23
vivek.s.vivek24-May-06 20:23 
AnswerRe: templates [modified] Pin
Nibu babu thomas24-May-06 20:36
Nibu babu thomas24-May-06 20:36 
vivek.s.vivek wrote:
Whether C++ templates and generic programmings concepts are same?.


We do generic programming using templates. Templates helps us to generalize a concept.

For example a simple sum function which calculates the sum of two ints can be redesigned to calculate sum of any number and return the same type of number. This can be done through templates. It's a compile time mechanism hence no runtime overhead too.

An example:

//function that calculates the sum of two ints without using templates... 
 
int Sum(int nNum1, int nNum2)
{
    return (nNum1 + nNum2);
}
//The above function can calculate the sum of only two ints
 
//for eg:
 
int nSum   = Sum(2, 4);
 
//What about two floats...
 
float fSum = (float)Sum((int)2.0f, (int)3.5f); //eek :eek:
 
 
 
//function that calculates the sum of any two number of the same type using templates...
 
template<class T> T Sum(T num1, T num2)
{
    return (num1 + num2);
}
 
//how to call this function
 
float    fSum = Sum<float>  (2.0f, 56.34f);
int      nSum = Sum<int>    (2, 56);
double   dSum = Sum<double> (2.002, 56.809);
 
//see this is what generic programming is all about



Nibu thomas
A Developer

Programming tips[^]  My site[^]

GeneralRe: templates [modified] Pin
Eytukan24-May-06 22:24
Eytukan24-May-06 22:24 
GeneralRe: templates [modified] Pin
Nibu babu thomas24-May-06 22:26
Nibu babu thomas24-May-06 22:26 
Questionwparm,lparm Pin
Scorpio24-May-06 20:22
Scorpio24-May-06 20:22 
AnswerRe: wparm,lparm Pin
Nibu babu thomas24-May-06 20:30
Nibu babu thomas24-May-06 20:30 
AnswerRe: wparm,lparm Pin
Sarath C24-May-06 20:31
Sarath C24-May-06 20:31 
GeneralRe: wparm,lparm Pin
Scorpio24-May-06 20:44
Scorpio24-May-06 20:44 
GeneralRe: wparm,lparm Pin
Sarath C24-May-06 21:19
Sarath C24-May-06 21:19 
Questionnew com port driver Pin
MyOwnShadow24-May-06 20:06
MyOwnShadow24-May-06 20:06 
AnswerRe: new com port driver Pin
NiceNaidu24-May-06 20:49
NiceNaidu24-May-06 20:49 
Questionsingleton inheritance Pin
Krishnatv24-May-06 19:55
Krishnatv24-May-06 19:55 
AnswerRe: singleton inheritance Pin
Nibu babu thomas24-May-06 20:16
Nibu babu thomas24-May-06 20:16 
QuestionCRichEditCtrl Pin
VinayCool24-May-06 19:47
VinayCool24-May-06 19:47 
AnswerRe: CRichEditCtrl Pin
Nibu babu thomas24-May-06 20:25
Nibu babu thomas24-May-06 20:25 
AnswerRe: CRichEditCtrl Pin
Steve Echols24-May-06 20:30
Steve Echols24-May-06 20:30 
GeneralRe: CRichEditCtrl Pin
VinayCool24-May-06 20:44
VinayCool24-May-06 20:44 
GeneralRe: CRichEditCtrl [modified] Pin
Steve Echols24-May-06 21:05
Steve Echols24-May-06 21:05 
GeneralRe: CRichEditCtrl [modified] Pin
VinayCool24-May-06 21:37
VinayCool24-May-06 21:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.