Re: C++ Coding Style
Low Zhen Lin <[email protected]> Tue, 23 Dec 2003 11:20:42 +0800
| Newsgroups | gmane.linux.zynot.devel |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Andreas Pokorny wrote:
|> ~ if (o.isa(Class(String)) cout << "I got a String!" <<
|> endl; ~ else if (o.isa(Class(Number)) cout << "I got a
|> Number!" << endl; ~ else if (o.isa(Class(Object)) cout << "I
|> got an Object!" << endl; ~ else cout << "I got something
|> wierd." << endl;
|>
|> Note that the 'if' lines up. When feasible, line up code to be
|> neater:
|>
|> ~ int i = 0; ~ char c = '\0'; ~ double d = 0.0; ~
|> void* p = 0;
|
|
| int i = 0; char c = '\0'; double d = 0.0; void * p = 0;
That's fine too...
| no, local variables should be as local as possible.
This breaks on some compilers... And isn't portable to C methinks. The
problem is that the compiler has to allocate stack space for the
variables right at the beginning of the function - not all compilers
like searching the whole body of code for variable declarations.
|> ~ length getLength() { return *new
|> Length(this->getLengthInCM(),Length::cm); }
|
| Avoid Memory leaks: You create a Length object using new, then the
| pointer get dereferenced, and you return an Object of type Length.
| So the return statement will copy that object again. So you created
| 2 Objects .. thats ok if you return by value. But the first object
| has been created on the heap and will not neither be destroyed nor
| deallocated when the method returns.
Feel free to write up object allocation and ownership guidelines. Also
feel free to use reference counting... I will be providing that in the
foundation libraries - GTK+ uses them too I think, and so does Qt if
I'm not mistaken.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQE/57SKv+6a/MPcjnERAsvzAJ478/Smxk6DQKFUVvCKKJ8p2DXqOACfdqdi
rdS4AYIWlVet8bxq3kCtmoo=
=pskU
-----END PGP SIGNATURE-----