Re: C++ Coding Style
Galik <[email protected]> Sun, 21 Dec 2003 14:20:27 +0000
| Newsgroups | gmane.linux.zynot.devel |
|---|---|
| Message-ID | <[email protected]> |
Chris Frey wrote:
>
>
>
>>'*' attached to typename, no spaces in declaration:
>>
>>~ const char* cstring;
>>~ int (*pfunc)(int, int);
>>
>>
>
>This I disagree with because it leads to confusion in declarations of
>lists of pointers. Which is correct?
>
> char* ptr1, ptr2;
>or
> char *ptr1, *ptr2; // correct
>
>Keeping the star with the variable keeps things clear.
>
>
>
Bah! This is the only construct where placing '*' by the identifier
makes sense. It is also a terrible thing to do. All declarations should
appear on a separate line. See Bjarne Stroustrup's The C++ Programming
Language...
>What about class member names? Do you prefix with 'm_' or suffix with '_'?
>
>
>
I prefer not to.
>>~ class Object
>>~ {
>>~ public:
>>~ explicit Object();
>>~ protected:
>>~ unsigned int refCount;
>>~ private:
>>~ Object(Object&) { }
>>~ };
>>
>>
>
>This looks new to me, and wastes precious screen space. I think public,
>protected, private should be along the class's '{' column, and the members
>in one indent.
>
> class Object
> {
> protected:
> int member_;
>
> public:
> Object();
> };
>
>
>
Hehe I prefer...
class Object
{
//---------------------------------------------------
protected:
//---------------------------------------------------
int member1;
int member2;
//---------------------------------------------------
private:
//---------------------------------------------------
int private1;
int private2;
};