0

I have tried using #include <generic> and #include <generic.h> but these are not recognised. I have tried consulting the manual but it does not help me.

So anyone know the correct name for this header file using Bloodshed Dev-C++?

Mat
  • 202,337
  • 40
  • 393
  • 406
Mr_leighman
  • 313
  • 1
  • 6
  • 22
  • What exactly do you mean by "generic classes"? C++ has no feature named like that. Or do you mean a class called "generic" from some 3rd party library? – PlasmaHH Apr 02 '12 at 18:51
  • A generic class is itself a macro that generates classes that all have the same general form – Mr_leighman Apr 02 '12 at 18:59
  • That's not how generic programming is done in C++. Where have you seen this before? – bames53 Apr 02 '12 at 19:00
  • @Mr_leighman: What made you think there is such a header, or such a set of macros in C++? – PlasmaHH Apr 02 '12 at 19:00
  • Well, In my text book it says so...and it says "consult this file and your system manual to determine all macros supplied in your generic.h" – Mr_leighman Apr 02 '12 at 19:05
  • Also, doesn't Dev-C++ use an ancient C++ compiler? You'd be better off using a modern IDE and compiler. You can get Visual Studio 11 beta for free and it's great. – bames53 Apr 02 '12 at 19:05
  • @Mr_leighman: Does it maybe refer to a file that comes with the textbook, where some of the textbook code is given to you? – PlasmaHH Apr 02 '12 at 19:07
  • @blame53 Programming in c++ by Paul M.Chirlian – Mr_leighman Apr 02 '12 at 19:07
  • @blame53 - No code with textbook included on disk!! – Mr_leighman Apr 02 '12 at 19:08
  • Yes - there are of course example code using the macro generic code included. – Mr_leighman Apr 02 '12 at 19:10
  • @Mr_leighman: If it is the same book I know, it is from 1990, doesn't know about templates, and is talking about its own header. Dump it. It is 22 years (!) older than the latest C++ standard. It contains nothing useful at all. It will only make things worse. What was considered C++ back then is now something totally different. – PlasmaHH Apr 02 '12 at 19:13
  • Well o.k then..That's news to me. I guess its something I should of checked before I started the book. I found the book easy to absorb and understand now I have to start all over again after 8 months of studying this book!!!- because you're saying its totally out of date. Great, Now - I think I will go and smoke a Hamlet cigar! – Mr_leighman Apr 03 '12 at 10:05

2 Answers2

3

<generic.h> is a header from ancient, pre-standard C++. In fact it's old even compared to pre-standard C++. I was used back when C++ was just a precompiler on top of C. Even if you could find a compiler that still supported this, using it would not be a good idea and you would not be learning C++ as it exists today.

Any book that mentions <generic.h> is probably twenty years out of date. Instead you should choose a book from The Definitive C++ Book Guide and List. If you're just learning to program I recommend Programming: Principals and Practice Using C++. If you're already familiar with programming in other languages then Accelerated C++ should be good.

The latest version of Dev-C++ is very old as well (though not nearly as old as <generic.h>) and newer, much better, compilers and IDEs are available for free. If you're on Windows then Visual Studio 11 beta should be your first choice. (assuming you're not also on an ancient version of Windows...)

Community
  • 1
  • 1
bames53
  • 86,085
  • 15
  • 179
  • 244
  • Just FYI, there have actually been some [recent independent updates](http://orwellengine.blogspot.com/) to Dev-C++. But yeah, I would still not recommend it over any of the alternatives. – Bart Apr 02 '12 at 19:24
  • Well o.k then..That's news to me. I guess its something I should of checked before I started the book. I found the book easy to absorb and understand now I have to start all over again after 8 months of studying this book!!!- because you're saying its totally out of date. Great, Now - I think I will go and smoke a Hamlet cigar! – Mr_leighman Apr 03 '12 at 09:55
2

C++ doesn't have generics like Java and C# do. C++ has a similar feature called templates, but there are no special headers to include for that. C++ supports templates intrinsically. You can use template types and functions by mentioning their names, along with the template argument type in angle brackets:

#include <vector>

// declare a variable of type std::vector<int>
std::vector<int> vector_of_ints;

The #include <vector> is to tell the compiler about the std::vector template class, not to tell the compiler how to use templates in general.

You can define new template types and functions with the template keyword:

// declare a function accepting and returning a type to be determined later
template <typename T>
T add_one(T x) {
  return x + 1;
}
Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • I would say templates have a use case that's similar to generics in Java and C#, but that doesn't make templates similar to Java/C# generics. – bames53 Apr 02 '12 at 19:02
  • Yes Thanks, I will try some variations with the help of your answer - not sure how to translate your answer to my answer but I am sure it will help, thanks – Mr_leighman Apr 02 '12 at 19:02
  • Well o.k then..That's news to me. I guess its something I should of checked before I started the book. I found the book easy to absorb and understand now I have to start all over again after 8 months of studying this book!!!- because you're saying its totally out of date. Great, Now - I think I will go and smoke a Hamlet cigar! – Mr_leighman Apr 03 '12 at 09:56