From: WJ on 20 Jan 2010 17:50 can "template" be used in .C file? I wanted to write a arameterized function, but "template" would not compile. I am thinking that the template keyword is not supported in .C file, but I just want to confirm. Thanks. WJ
From: Giovanni Dicanio on 20 Jan 2010 18:21 "WJ" <WJ(a)discussions.microsoft.com> ha scritto nel messaggio news:84083384-1716-4788-B3B5-1E564791DB57(a)microsoft.com... > can "template" be used in .C file? > > I wanted to write a arameterized function, but "template" would not > compile. > I am thinking that the template keyword is not supported in .C file, but I > just want to confirm. Templates are C++ only. In some cases you may want to use the preprocessor to simulate templates in C, e.g. // C++ with templates: template <typename T> T Square( const T & x ) { return x*x; } // C with preprocessor: #define SQUARE( x ) (x) * (x) Of course, with preprocessor you don't have the robusteness and expressivity of C++ templates. HTH, Giovanni
From: Drew on 20 Jan 2010 18:23 Short answer is no. But you can compile the code as C++ either by renaming with a .cpp extension or specifying Compile as C++ Code under properties for the file under C/C++/Advanced. Drew "WJ" <WJ(a)discussions.microsoft.com> wrote in message news:84083384-1716-4788-B3B5-1E564791DB57(a)microsoft.com... > can "template" be used in .C file? > > I wanted to write a arameterized function, but "template" would not > compile. > I am thinking that the template keyword is not supported in .C file, but I > just want to confirm. > > Thanks. > > WJ
From: Joseph M. Newcomer on 20 Jan 2010 23:41 C does not have the concept of templates. That's why it is called C. If it supported templates, it would be called C++. joe On Wed, 20 Jan 2010 14:50:09 -0800, WJ <WJ(a)discussions.microsoft.com> wrote: >can "template" be used in .C file? > >I wanted to write a arameterized function, but "template" would not compile. >I am thinking that the template keyword is not supported in .C file, but I >just want to confirm. > >Thanks. > >WJ Joseph M. Newcomer [MVP] email: newcomer(a)flounder.com Web: http://www.flounder.com MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Tom Serface on 21 Jan 2010 02:15 Several people have already answered your question, but I just wanted to add that I don't see any particular reason to use vanilla "C" any longer. Any platform that can support C would certainly support C++ these days and almost all of the C++ compilers support templates in one form or another. Unless you need something specific for calling convention, I wouldn't use C at all. That gets rid of the confusion. Tom "WJ" <WJ(a)discussions.microsoft.com> wrote in message news:84083384-1716-4788-B3B5-1E564791DB57(a)microsoft.com... > can "template" be used in .C file? > > I wanted to write a arameterized function, but "template" would not > compile. > I am thinking that the template keyword is not supported in .C file, but I > just want to confirm. > > Thanks. > > WJ
|
Next
|
Last
Pages: 1 2 3 Prev: How can I get a MFC DLL with NO own CWinApp/AfxGetApp() ? Next: mfc debugging |