Solved

warning C4270

Posted on 1997-06-02
3
192 Views
Last Modified: 2010-04-10
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.
0
Comment
Question by:cgardner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 11

Expert Comment

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

.B ekiM
0
 
LVL 5

Accepted Solution

by:
yonat earned 50 total points
ID: 1163795
The declaration
String * m_pName;
will definetily cause problems, since you don't set memory space
for the String pointed by m_pName. In other words, m_pName does
not point to a valid String. Instead, use
String * m_pName = new String;
or just plain old
String m_Name;
If you use the latter, then m_Name = setName() should work.
But, like mikeblass said, it depends on the definition of
String::operator=(const String&). Form the warning, I suspect
that it is wrongly declared String::operator=(String&) - without
the const.
0
 

Author Comment

by:cgardner
ID: 1163796
Thanks, your right.. I forgot the const in operator =
which caused the C4270

also I forgot to initialize..  Bonus


 

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question