Quantcast
Channel: When should I use typedef in C++? - Stack Overflow
Browsing latest articles
Browse All 14 View Live

Answer by Rana Vivek for When should I use typedef in C++?

1 practical example of typedef is size_t. It is guaranteed to be big enough to contain the size of the biggest object the host system can handle. The maximum permissible size is dependent on the...

View Article



Answer by sneha for When should I use typedef in C++?

Typedef allows flexibility in your class. When you want to change the data type in the program, you do not need to change multiple locations but just need to change one occurrence.typedef <datatype...

View Article

Answer by Imran Al Noor for When should I use typedef in C++?

There is one another use case to use typedef is when we want to enable a kind of Container Independent code (but not exactly!)Let us say you have class:Class CustomerList{public: //some...

View Article

Answer by Ztyx for When should I use typedef in C++?

typedef allows to not only have an alias for complex types, but gives you a natural place to document a type. I sometimes use it for documentation purposes.There are also times when I use an array of...

View Article

Answer by xtofl for When should I use typedef in C++?

... and you Don't Need a Typedef for an enum or a struct.Or do you?typedef enum { c1, c2 } tMyEnum;typedef struct { int i; double d; } tMyStruct;can be better written asenum tMyEnum { c1, c2 }struct...

View Article


Answer by peterchen for When should I use typedef in C++?

Just to provide some examples for the things said: STL containers. typedef std::map<int,Froboz> tFrobozMap; tFrobozMap frobozzes; ... for(tFrobozMap::iterator it=frobozzes.begin(); it!=map.end();...

View Article

Answer by dsimcha for When should I use typedef in C++?

One good reason to use typedef is if the type of something may change. For example, let's say that for now, 16-bit ints are fine for indexing some dataset because for the foreseeable future, you'll...

View Article

Answer by Emiliano for When should I use typedef in C++?

typedef is useful in a lot of situations.Basically it allows you to create an alias for a type. When/if you have to change the type, the rest of the code could be unchanged (this depends on the code,...

View Article


Answer by Jason Punyon for When should I use typedef in C++?

In Bjarne's book he states that you can use typedef to deal with portability problems between systems that have different integer sizes. (this is a paraphrase)On a machine where sizeof(int) is 4 you...

View Article


Answer by yesraaj for When should I use typedef in C++?

use with function pointerHide Function Pointer Declarations With a typedefvoid (*p[10]) (void (*)() );Only few programmers can tell that p is an "array of 10 pointers to a function returning void and...

View Article

Answer by Leonidas for When should I use typedef in C++?

Whenever it makes the source clearer or better to read.I use kind of typedef in C# for generics/templates. A "NodeMapping" is just better to read/use and understand then a lot of "Dictionary<string,...

View Article

Answer by j_random_hacker for When should I use typedef in C++?

Template Metaprogrammingtypedef is necessary for many template metaprogramming tasks -- whenever a class is treated as a "compile-time type function", a typedef is used as a "compile-time type value"...

View Article

Answer by moonshadow for When should I use typedef in C++?

Real-world uses of typedef:providing friendly aliases for long-winded templated typesproviding friendly aliases for function pointer typesproviding local labels for types, e.g.:template<class _T>...

View Article


When should I use typedef in C++?

In my years of C++ (MFC) programming in I never felt the need to use typedef, so I don't really know what is it used for. Where should I use it? Are there any real situations where the use of typedef...

View Article
Browsing latest articles
Browse All 14 View Live




Latest Images