CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2008
    Posts
    78

    '=' operator can not be overloaded

    Hello,

    I have a string x which is either null or has some value. I have to assign this value to another string y. With normal '=' (y = x) operation, I get an error if string x has null value.

    I have to check first with the help of "if" statement

    Code:
    if(x != "")    //or catch exception here
        y = x;
    I have to apply above code in my program everywhere I try to assign one string value to another string (and have to be careful). I would have preferably overloaded '=' operator, but have just leant that it is not possible to overlaod '='.

    Can someone please suggest me another way of doing it?

    Regards
    Ricky

  2. #2
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: '=' operator can not be overloaded

    There shouldn't be any problem with assigning 'null' to a string variable. The below code is, if I'm not mistaken, perfectly valid:

    Code:
    string y = "something";
    string x = null;
    
    y = x;
    What is the error / exception you are experiencing?
    It's not a bug, it's a feature!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured