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
  • 74,482
  • 9
  • 111
  • 149
Ashwin
  • 411
  • 1
  • 10
  • 28

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
  • 74,840
  • 36
  • 166
  • 272
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,632
  • 2
  • 37
  • 67
  • 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