Yes I found that out in the meantime. Was just confused by the strange overload.
Sorry.
Kurt

06-30-2007

noobcpp

I am learning. So whatever I'll do now would be strange.

06-30-2007

CornedBee

Don't mix learning two things at once. If you want to learn pointers, learn pointers. (But learn both how and when to use them. The learning effect of using new Java-style is just about nil.) If you want to learn operator overloading, learn operator overloading. Don't mix the two. It leads to strange results, as you've discovered.

06-30-2007

noobcpp

I am actually a very experienced PHP programmer that's why I am much familiar with new and -> operator
And -> can be used with pointer only.
And that's why I've a tendency to use new.else it looks like Function not like object to myself.
And what can I do if new operator involves Pointer.

06-30-2007

anon

In this case you don't need to learn but unlearn about pointers :)

06-30-2007

noobcpp

Quote:

Originally Posted by anon

In this case you don't need to learn but unlearn about pointers :)

Hey Why ??
Is there any way of using new without pointers ??
If yes then Please tell me.

06-30-2007

ZuK

Quote:

Originally Posted by noobcpp

Hey Why ??
Is there any way of using new without pointers ??
If yes then Please tell me.

Sorry to disappoint you. All that operator new does is creating an object and returning pointer to that object. There is no way to access that object without using that pointer.
Kurt

06-30-2007

noobcpp

OK.
Thanks Pointer is Cool then.
But I still didn't Understand

Quote:

Originally Posted by anon

you don't need to learn but unlearn about pointers

06-30-2007

ZuK

Quote:

Originally Posted by noobcpp

OK.
Thanks Pointer is Cool then.

Most C++ users will disagree on that. They think that pointers should not be used unless there is no other way to get a problem solved ( it's too easy to create memory leaks when using pointers ).
Kurt

06-30-2007

noobcpp

In PHP its too hard to make a parser.It has only refference although I've atlast Made it.
Its a HTML / XML / wml / ...ML Parser Compleately made by PHP (95 &#37; made still now)
With it you can Parse XMl with SQL like Statement. and Its very fast It takes just 0.02 MICROsecond to parse a Standerd XML File
Now I wanna Convert it to C and C++ also
Thats why I found pointer and refference in C++ Very Cool.
PHP keeps Pointer Internally But dont lets us to use it like C++ or C.

06-30-2007

anon

About why it's wrong to return a pointer to object from overloaded = operator.

With built-in types it is normal to write the following to set both a and b to c.

Code:

int a, b, c = 42;
a = b = c; // means: a = (b = c);

If you return a pointer from your operator overload, you couldn't use this syntax any more. Instead you'll need to dereference the returned pointer.

Code:

MyClass a, b, c;
a = *(b = c);

If you added more assignments to the chain, it would look even worse.

That's why this overload should return a reference instead.

06-30-2007

noobcpp

Oh! I see.

06-30-2007

CornedBee

C++ is not PHP. If you learn a new language, you will have to learn the best practices for this language, else your code will be bad. For C++, using pointers only where necessary is a best practice.