Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler not allowing to define a compiler-generated constructor

Tags:

c++

I'm trying to define the constructor that compiler generates automatically and resulted in an compilation error. Here is my code:

class myclass
 {
   public:
       void Test_Func()
       {}
 };
myclass::myclass()
{
}

Is compiler doing anything in addition for a simple class like above. Here is the error that I got in MSVC compiler:

"error C2600: 'myclass::myclass' : cannot define a compiler-generated special member function (must be declared in the class first)"
like image 348
Pranesh Avatar asked Dec 17 '22 13:12

Pranesh


1 Answers

The synthesised constructor is both declared and defined. You may not define it yourself.

You'll have to declare your own constructor in order to provide an implementation.

[special] (2003 wording, 12/1) says:

The default constructor (12.1), copy constructor and copy assignment operator (12.8), and destructor (12.4) are special member functions. The implementation will implicitly declare these member functions for a class type when the program does not explicitly declare them, except as noted in 12.1. The implementation will implicitly define them if they are used, as specified in 12.1, 12.4 and 12.8. Programs shall not define implicitly-declared special member functions.

like image 78
Lightness Races in Orbit Avatar answered Jan 19 '23 00:01

Lightness Races in Orbit