I've come across some C++ code that has the following:
typedef Request Request;
Is this just a no-op or does this typedef actual have an effect, and if so, what effect does it have?
If Request
is only passed as a parameter it seems to be a opaque pointer.
There should be a
typedef struct Request Request
somewhere in the code. (see comments on your question)
This is used to define an API and hide implementation details. So you can later change the implementation without changing the API again.
The client does not need to know anything about the acutal type - its just kind of a handle.
Everything you want to do with it has to be done with the api methods (creation, delete, load, init, ...)
Usually the handle Request
will be casted to something more meaningfull in the implementation of the api. This was/is usually done in old C.
You can read all rules relative to typedef specifier for C++2003 ANSI ISO IEC 14882 2003 in section 7.1.3. In 7.1.3, 2) it have been said the identity typedef is allowed if the name already refers to some type.
This is legal:
And that it is not:
The standard has a specific example relating to this. C++2003, §7.1.3/2:
In 7.1.3, 3) it have been said that use typedef to redefine type to alias to another type is prohibited