0

This is a part of my code ....
//samlple.h........

class Manager{            
public:                                                
    Manager(cmd::Processor *cp);                    
    virtual ~Manager(void);                                
protected:                                       
    cmd::Processor  *m_Processor;                                       

};         

//samlple.cpp........

//Default constructor                  

Manager::Manager(                
    cmd::Processor  *cp           
) : m_commandProcessor(cp)                
    {            
    g_MgrCommand = new MgrCommand(this);                
}        

After running this I am getting the below warning :
Sample.cpp(97): Info 1732: new in constructor for class 'Manager' which has no assignment operator ........

I am new to c++ coding ...
Can you tell me how can I write copy constructor and assignment operator for my class to remove this warning

Elias Van Ootegem
  • 70,983
  • 9
  • 108
  • 145
Ashwin
  • 391
  • 1
  • 8
  • 27

2 Answers2

0

You can declare an operator= member function:

Manager& Manager::operator=(const Manager&) {
    // ...
    return (*this);
}

Of course the first argument of the function can be anything you want it to be.

Shoe
  • 72,892
  • 33
  • 161
  • 264
0

You don't have to implement the copy c'tor/assignment.

The point is that, unless you implement them yourself, the compiler implements it automatically by member-wise copy. In your specific case this auto-generated code will be incorrect, since you'll have several objects pointing to the same allocated MgrCommand.

You should either implement the c'tor/assignment operator correctly (probably by allocating a separate instance of MgrCommand in every object), or disable them.

valdo
  • 12,216
  • 1
  • 35
  • 62
  • I have this warning also in code : Info 1733: new in constructor for class 'Manager' which has no copy constructor – Ashwin Jan 17 '14 at 14:39