From -928203035022431574 X-Google-Language: ENGLISH,ASCII X-Google-Thread: f78e5,c2b14dd76a592e12 X-Google-Attributes: gidf78e5,public From: vaps4bm@prism.gatech.edu (Brian McNamara!) Subject: Re: function objects inside functions Date: 2000/11/27 Message-ID: <8vu8ic$iuo$1@news-int.gatech.edu>#1/1 X-Deja-AN: 698339882 Approved: Fergus Henderson , moderator of comp.std.c++ References: X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f X-Complaints-To: abuse@demon.net X-Mail2News-Path: news.demon.net!mulga.cs.mu.oz.au X-Trace: mail2news.demon.co.uk 975351260 mail2news:10980 mail2news mail2news.demon.co.uk Organization: Georgia Institute of Technology X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) NNTP-Posting-Date: 27 Nov 2000 18:18:52 GMT Newsgroups: comp.std.c++ "Juan Vali�o" once said: >I try to use a function-object near it use: >void foo() { > struct Print{ void operator()(int x) { cout << x; } }; > for_each(aVector.begin(), aVector.end(), Print()); >}; >C++Builder refuses it unless I put the Print declaration out of foo. >Is this compiler ok?, In that case, is there any solution (without template >metaprogramming)?. The compiler is right; the code is illegal. Template types need external linkage. The solution, as you said, is just to define Print outside the function. -- Brian McNamara --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.research.att.com/~austern/csc/faq.html ] [ Note that the FAQ URL has changed! Please update your bookmarks. ]