Alex Rivera | Logout

Does the typename keyword exist in C++, for backwards compatibility with “C templates?”

Asked 2010-02-25T19:53:37.433
19

I’m taking a C++ class, and my teacher mentioned in passing that the typename keyword existed in C++ (as opposed to using the class keyword in a template declaration), for backwards compatibility with “C templates.”

This blew my mind. I’ve never seen or heard tell of anything like C++’s templates (except, perhaps, the preprocessor… and that’s not really the same thing at all) in ANSI C. So, did I miss something huge somewhere, or is this a really esoteric extension by gcc or something, or is my teacher way off-base?

Edit
Report

3 Answers

26

I think your teacher is off base.

See Stan Lippman's post: Why C++ Supports both Class and Typename for Type Parameters for the real reason why C++ supports both.

answered 2010-02-25T19:56:51.337
0

This doesn't seem right. typename is not a reserved word at all in C.

Perhaps they misspoke/remembered and were thinking of "C with Classes".

answered 2010-02-25T19:58:01.390
0

I wish to say that C really don't have a native template stuff, however, you can make it works fine with some kind of a MetaProgramming, take a look around the web you will find how to...

Another important thing to say is that C is a programming language to general purpose, so a lot of things like Object Orientation, template and some other things can be done with a little more effort.

Projects like Gnome are proof that it can be done and very well.

P.S.: Sorry about my terrible english!!!

answered 2013-07-19T02:40:28.767

Your Answer