|
|
|
|
vlad wrote: |
---|
By the way never use such a syntax as Account* attachedAccount; |
Account * attachedAccount;
, makes more sense to me (especially when you start bringing const
in to it)
@Disch I prefer that syntax because the * is part of the type, so keeping it with the type makes more sense. |
It has no sense simply because it contradicts the C/C++ grammar. |
Moreover it has different meaning in C#. |
If your aim is to confuse readers then you selected the right way. |
@cire It has no sense simply because it contradicts the C/C++ grammar. No, it doesn't. |
|
|
T* D
it kind of think meh!
vlad wrote: |
---|
I already wrote very clear for the author of the topic "Do not repeat this stupidity after some idiots." |
type* name;
You are wrong. There is no such a type specifier as T* in C/C++. Declarators and type specifiers are different things. Read the C++ Standard what are declarators and what are type specifiers. |
The three components of a simple-declaration are the attributes (7.6), the specifiers (decl-specifier-seq; 7.1) and the declarators (init-declarator-list). The specifiers indicate the type, storage class or other properties of the entities being declared. The declarators specify the names of these entities and (optionally) modify the type of the specifiers with operators such as * (pointer to) and () (function returning). |
Is "int* p;" right or is "int *p;" right? Both are "right" in the sense that both are valid C and C++ and both have exactly the same meaning. As far as the language definitions and the compilers are concerned we could just as well say "int*p;" or "int * p;" The choice between "int* p;" and "int *p;" is not about right and wrong, but about style and emphasis. C emphasized expressions; declarations were often considered little more than a necessary evil. C++, on the other hand, has a heavy emphasis on types. A "typical C programmer" writes "int *p;" and explains it "*p is what is the int" emphasizing syntax, and may point to the C (and C++) declaration grammar to argue for the correctness of the style. Indeed, the * binds to the name p in the grammar. A "typical C++ programmer" writes "int* p;" and explains it "p is a pointer to an int" emphasizing type. Indeed the type of p is int*. I clearly prefer that emphasis and see it as important for using the more advanced parts of C++ well. The critical confusion comes (only) when people try to declare several pointers with a single declaration: int* p, p1; // probable error: p1 is not an int* Placing the * closer to the name does not make this kind of error significantly less likely. int *p, p1; // probable error? Declaring one name per declaration minimizes the problem - in particular when we initialize the variables. People are far less likely to write: int* p = &i; int p1 = p; // error: int initialized by int* And if they do, the compiler will complain. Whenever something can be done in two ways, someone will be confused. Whenever something is a matter of taste, discussions can drag on forever. Stick to one pointer per declaration and always initialize variables and the source of confusion disappears. |
template < typename T > void foo( const T& r )
is "right", or template < typename T > void foo( const T &r )
is "right".Vlad, what's up man? You're usually pretty mild mannered. |
No, he's not. Insulting people who disagree with him, and even insulting beginners who don't understand his posts, is pretty common behaviour for Vlad |