Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Any reason to use C?

Author: Steffen Jakob

Date: 22:19:15 07/28/03

Go up one level in this thread


Hi Dieter!

On July 28, 2003 at 19:00:41, Dieter Buerssner wrote:

>On July 28, 2003 at 18:26:29, Gerd Isenberg wrote:
>
>>References, function inlining and namespaces are enaugh to use C++.
>
>Gerd, references is enough for me, to avoid C++. In the "old days", when I read
>code with a function call, like foo(a), I was sure, that a will be the same
>after the function call, than before. With C++, I cannot be sure anymore. If I
>want to make a changable by a function call, I use &a in C. All pretty much self
>documenting. Not anymore in C++.

An advantage of references compared to pointers is that you no longer have to
check if the parameter is a 0 pointer. If 0 is a legal value than of course you
cannot use references anyway [*].

void foo(MyClass *obj) {
    if (obj == 0) {
        throw "unexpected 0 pointer parameter in foo()";
    }
    obj->changeMyState();
}

vs.

void foo(MyClass &obj) {
    obj.changeMyState();
}

Greetings,
Steffen.

[*] Yes, I know that it's theoretically possible to reference a "0 pointer
object".



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.