Link to home
Start Free TrialLog in
Avatar of cgardner
cgardner

asked on

warning C4270

warning C4270: 'initializing' : do not initialize a non-const 'class ::String __near &' with a non-lvalue 'class ::String ' function return

This is my first test question.
I would like to know if this is a legitimate warning of if it is a bug in the compiler(MS C++ 1.52).

in book Teach Yourself C++ in 21 days ( Perry)
   there is a reference that it is a bug.
   (sorry i dont know the page)

here is the statement that gives the warning.    
    *m_pName = setName();  : warning C4270 etc.

the relevant declarations are
    String * m_pName;
    String setName();
 
the definition is

String Column::setName()
{
   String ans="dummy";
   return ans;
}

looking at the statement
   *m_pName = setName();

The String pointed to by *m_pName calls it's  operator= and copies in the contents of the String in setName(). This is precisely what I want it to do and cannot  see why the compiler has any justification for complaining.
Avatar of mikeblas
mikeblas

To get an accurate answer, you'll need to show the definition and declaration of operator=() in the String class you wrote.

.B ekiM
ASKER CERTIFIED SOLUTION
Avatar of yonat
yonat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cgardner

ASKER

Thanks, your right.. I forgot the const in operator =
which caused the C4270

also I forgot to initialize..  Bonus