Monday, May 29, 2006

The weird world of C++

Today I just discovered that the matrix I had coded yesterday was completely messed up. Well, I am learning C++, and I start wondering if there is any logic underlying the semantics of this language. After dating Java, and enjoying the rude elegance of ANSI C, what is C++? Basically, There are three main ways you can refer to a data object in C++: As the object itself - by value; As the memory address of the object - by pointer; with an alias to the object - by reference. God, what is that? Why to add so much complexity to a programming language? Anyways, if you are as puzzled as me, you can find some very nice explanations about all this complexity in Mr. Crawford's webpage. Although I am frustrated with C++, I am getting the feeling that this language is like a wild horse, that, after tamed, may be a loyal friend.

Oh, about today. Well, the matrix class from yesterday now works fine. It is necessary to pass the objects that it holds by references. I just discovered that when a value is returned from a function (I thought it only occurred when the object was passed as parameter...), it is returned by value. The fixed code is here. A program that uses it is this one here.

0 Comments:

Post a Comment

<< Home