"no default constructor exists for class" Error in C
When attempting to instantiate an instance of the GameCryptography class without providing a constructor argument, an IntelliSense error message indicating that no default constructor exists for the Blowfish class is encountered.
This error occurs because the GameCryptography constructor attempts to initialize an embedded instance of Blowfish without providing a constructor argument. By default, C synthesizes a constructor for a class without a user-defined one. However, if the class does have a user-defined constructor, the default constructor is not synthesized.
To resolve the error, one of the following strategies can be implemented:
Blowfish() : _algorithm(CBC) {}
GameCryptography(unsigned char key[]) : _blowfish(CBC) {}
class Blowfish { public: Blowfish(BlowfishAlgorithm algorithm) {} Blowfish() = default; };
The above is the detailed content of Why Does \'no default constructor exists for class\' Appear in C When Instantiating a Class with an Embedded Class Lacking a Default Constructor?. For more information, please follow other related articles on the PHP Chinese website!