Click here to Skip to main content
15,912,507 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: c?C++ Pin
CPallini23-Mar-09 4:01
mveCPallini23-Mar-09 4:01 
VuNic wrote:
For example..


If you do weird things in the = operator (re-)definition, for instance, i.e. if you write it (implicitely) assuming it will be never used to do self-assignment. Have a look at the following code
(please note, it is silly, written just to spot the point; moreover no check is done on memory allocation, for brevity)

class Foo
{
  static const int N = 10;
  char * _buf;
public:
  Foo(char c){_buf = new char [N]; memset(_buf, c, N);}
  Foo & operator=(const Foo & foo)
  {
    if ( _buf )
    {
      delete _buf;
      _buf = new char[N];
    }
    memcpy(_buf, foo._buf, N);
    return *this;
  }
  Foo(const Foo & foo){...}
};

void main()
{
  Foo f('A');
  f = f;
}


Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke

[My articles]

QuestionRe: c?C++ Pin
led mike23-Mar-09 4:28
led mike23-Mar-09 4:28 
AnswerRe: c?C++ Pin
CPallini23-Mar-09 7:27
mveCPallini23-Mar-09 7:27 
GeneralRe: c?C++ Pin
led mike23-Mar-09 7:41
led mike23-Mar-09 7:41 
GeneralRe: c?C++ Pin
CPallini23-Mar-09 7:51
mveCPallini23-Mar-09 7:51 
GeneralRe: c?C++ Pin
led mike23-Mar-09 7:56
led mike23-Mar-09 7:56 
GeneralRe: c?C++ Pin
Pankaj D.Dubey23-Mar-09 19:52
Pankaj D.Dubey23-Mar-09 19:52 
GeneralRe: c?C++ Pin
CPallini23-Mar-09 22:27
mveCPallini23-Mar-09 22:27 
AnswerRe: c?C++ Pin
led mike23-Mar-09 4:38
led mike23-Mar-09 4:38 
QuestionGetSystemTime() Pin
includeh1023-Mar-09 2:21
includeh1023-Mar-09 2:21 
AnswerRe: GetSystemTime() Pin
CPallini23-Mar-09 3:06
mveCPallini23-Mar-09 3:06 
Questionerror C2248 Pin
susanne123-Mar-09 1:53
susanne123-Mar-09 1:53 
AnswerRe: error C2248 Pin
TinyDevices23-Mar-09 1:59
professionalTinyDevices23-Mar-09 1:59 
GeneralRe: error C2248 Pin
susanne123-Mar-09 2:17
susanne123-Mar-09 2:17 
AnswerRe: error C2248 Pin
Cedric Moonen23-Mar-09 1:59
Cedric Moonen23-Mar-09 1:59 
GeneralRe: error C2248 Pin
susanne123-Mar-09 2:16
susanne123-Mar-09 2:16 
GeneralRe: error C2248 Pin
Cedric Moonen23-Mar-09 2:28
Cedric Moonen23-Mar-09 2:28 
GeneralRe: error C2248 Pin
susanne123-Mar-09 3:21
susanne123-Mar-09 3:21 
GeneralRe: error C2248 Pin
Cedric Moonen23-Mar-09 3:27
Cedric Moonen23-Mar-09 3:27 
Questionapplication for windows mobile Pin
trioum23-Mar-09 1:28
trioum23-Mar-09 1:28 
AnswerRe: application for windows mobile Pin
CPallini23-Mar-09 1:29
mveCPallini23-Mar-09 1:29 
AnswerRe: application for windows mobile Pin
Eytukan23-Mar-09 1:40
Eytukan23-Mar-09 1:40 
QuestionProblem with my c++ project :'( Pin
Neal beavis23-Mar-09 1:08
Neal beavis23-Mar-09 1:08 
QuestionRe: Problem with my c++ project :'( Pin
CPallini23-Mar-09 1:13
mveCPallini23-Mar-09 1:13 
AnswerRe: Problem with my c++ project :'( Pin
Neal beavis23-Mar-09 1:18
Neal beavis23-Mar-09 1:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.