Thread: Operator Overload = Not Working

  1. #16
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Yes I found that out in the meantime. Was just confused by the strange overload.
    Sorry.
    Kurt

  2. #17
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    I am learning. So whatever I'll do now would be strange.

  3. #18
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #19
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    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.
    Last edited by noobcpp; 06-30-2007 at 06:06 AM.

  5. #20
    The larch
    Join Date
    May 2006
    Posts
    3,573
    In this case you don't need to learn but unlearn about pointers
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  6. #21
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    Quote Originally Posted by anon View Post
    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.

  7. #22
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by noobcpp View Post
    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

  8. #23
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    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
    Last edited by noobcpp; 06-30-2007 at 07:12 AM.

  9. #24
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by noobcpp View Post
    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

  10. #25
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    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 % 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.

  11. #26
    The larch
    Join Date
    May 2006
    Posts
    3,573
    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.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  12. #27
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    Oh! I see.

  13. #28
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    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.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  14. #29
    Registered User
    Join Date
    Jun 2007
    Posts
    219
    I think you are right.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function not working
    By sloopy in forum C Programming
    Replies: 31
    Last Post: 11-12-2005, 08:08 PM
  2. Program Not working Right
    By raven420smoke in forum C++ Programming
    Replies: 2
    Last Post: 09-16-2005, 03:21 AM
  3. Trying to eject D drive using code, but not working... :(
    By snowfrog in forum C++ Programming
    Replies: 3
    Last Post: 05-07-2005, 07:47 PM
  4. x on upper right corner not working
    By caduardo21 in forum Windows Programming
    Replies: 1
    Last Post: 02-20-2005, 08:35 PM
  5. cygwin -> unix , my code not working properly ;(
    By CyC|OpS in forum C Programming
    Replies: 4
    Last Post: 05-18-2002, 04:08 AM