Click here to Skip to main content
15,910,886 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Database Application Design Pin
valikac28-May-04 14:00
valikac28-May-04 14:00 
GeneralRe: Database Application Design Pin
asv28-May-04 15:25
asv28-May-04 15:25 
Generalvisual c++ help hanging Pin
crazymike193828-May-04 0:27
crazymike193828-May-04 0:27 
GeneralRe: visual c++ help hanging Pin
jmkhael28-May-04 0:58
jmkhael28-May-04 0:58 
GeneralTaskbar icon mouse messages and keyboard modifiers Pin
cheesepirate28-May-04 0:24
cheesepirate28-May-04 0:24 
QuestionFunction template passed as typename argument? Pin
Indrawati28-May-04 0:12
Indrawati28-May-04 0:12 
AnswerRe: Function template passed as typename argument? Pin
Ryan Binns28-May-04 0:53
Ryan Binns28-May-04 0:53 
AnswerRe: Function template passed as typename argument? Pin
cheesepirate28-May-04 0:53
cheesepirate28-May-04 0:53 
Problem 1:

Your template functions aren't quite right (I didn't notice at first myself)
They should look like this

<br />
template <typename arg, typename T><br />
arg Fun(arg i1, arg i2, T func)<br />
{<br />
	return func(i1, i2);<br />
}<br />
<br />
template <typename T><br />
T maxi(T o1, T o2)<br />
{<br />
	return (o1 > o2 ? o1: o2);<br />
}<br />


Problem 2:
You can't use a function template as a function argument. That means the even with the correct definitions, it still won't work. Harrumph!

Solution:
Functors are like functions and classes all in one go - the STL uses them in the collection classes to order elements.
I re-wrote the functions like this...
#include <iostream>

using namespace std;

template <typename T>
struct Maxi
{
	T operator () (T o1, T o2)
	{
		return (o1 > o2 ? o1: o2);
	}
};

template <typename arg, typename Func = Maxi <arg> >
struct Fun
{
	arg operator () (arg i1, arg i2)
	{
		Func func;
		return func(i1, i2);
	}
};

int main(int argc, _TCHAR* argv[])
{
	int a (10), b (15);
	Fun <int> fun;

	cout << fun(a, b) << endl;
	return 0;
}


Lo and behold, I get 15 as my output! Ask anything you're unclear about and I'll try and clarify Smile | :)
GeneralRe: Function template passed as typename argument? Pin
toxcct28-May-04 1:10
toxcct28-May-04 1:10 
GeneralRe: Function template passed as typename argument? Pin
cheesepirate28-May-04 2:23
cheesepirate28-May-04 2:23 
AnswerRe: Function template passed as typename argument? Pin
toxcct28-May-04 1:12
toxcct28-May-04 1:12 
GeneralProblem subclassing list of owner-drawn combobox Pin
Paul Vickery27-May-04 23:46
professionalPaul Vickery27-May-04 23:46 
GeneralRe: Problem subclassing list of owner-drawn combobox Pin
Paul Vickery28-May-04 1:22
professionalPaul Vickery28-May-04 1:22 
QuestionHow to save GDI+ bmp as CMYK color GDI+ bmp Pin
pubududilena27-May-04 23:44
pubududilena27-May-04 23:44 
Questionchar* arr = &#8220;Nisse&#8221;; ? Pin
anderslundsgard27-May-04 23:34
anderslundsgard27-May-04 23:34 
AnswerRe: char* arr = &#8220;Nisse&#8221;; ? Pin
Roger Allen27-May-04 23:38
Roger Allen27-May-04 23:38 
AnswerRe: char* arr = &#8220;Nisse&#8221;; ? Pin
toxcct27-May-04 23:38
toxcct27-May-04 23:38 
AnswerRe: char* arr = &#8220;Nisse&#8221;; ? Pin
jmkhael28-May-04 0:55
jmkhael28-May-04 0:55 
Answer[Message Deleted] Pin
Naren Neelamegam28-May-04 19:58
Naren Neelamegam28-May-04 19:58 
GeneralRe: char* arr = &#8220;Nisse&#8221;; ? Pin
toroso7328-May-04 21:04
toroso7328-May-04 21:04 
GeneralExperts pls help ! General question Pin
Member 115017627-May-04 21:49
Member 115017627-May-04 21:49 
Generalfullscreen dialog control Pin
Bilge Kaan27-May-04 21:30
Bilge Kaan27-May-04 21:30 
GeneralRe: fullscreen dialog control Pin
Ryan Binns28-May-04 0:57
Ryan Binns28-May-04 0:57 
QuestionHow can i make ComboBox read only Pin
Zeeshan Bilal27-May-04 20:39
Zeeshan Bilal27-May-04 20:39 
AnswerRe: How can i make ComboBox read only Pin
toxcct27-May-04 21:53
toxcct27-May-04 21:53 

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.