Question

This is a question of Best practices.

I have implemented a LinkeList (https://github.com/ivanseidel/LinkedList) and it works fine.

The thing is, I'm writing a code that is repeatedly having things like: LinkedList<Beat>, which in my case, is a Rithm, but Rithm is not a type, class or anything, it's just how I see it.

I want a way of simplifying that name, without creating an extended class of LinkedList or anything. Just some way of replacing it.

I have tried with typedef:

typedef LinkedList<Beat> Rithm;

And also with a define (NAHH... I don't like it either)

#define Rithm LinkedList<Beat>

Is there a "correct" way of doing this?

Était-ce utile?

La solution

typedef wiki also says the same:

The purpose of typedef is to form complex types from more-basic machine types1 and assign simpler names to such combinations. They are most often used when a standard declaration is cumbersome, potentially confusing, or likely to vary from one implementation to another.

One should give some thought to naming the typedef as well.

I use the naming conventions used in Dave Hanson's C Interfaces and Implementations: a type is named with the module name and a capital T. So for example, the type of sequences is Seq_T, and the type of hash tables is Table_T.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top