My C++ class is looking for the default constructor of another object, Throwing error.
I am working on a simple C++ Legacy application. From a class, I am declaring an object of another class in its header file.
In the class constructor, I am trying to call its parameter'ized constructor.
But my program shows the following error as no default constructor.
Derived class Header file
#pragma once
#include "Base.h"
class CDerived :
public CBase
{
public:
// CDerived(); // Commented this out
CDerived(char a);
};
Derived Class Source
#include "Derived.h"
// Only one constructor definition
CDerived::CDerived(char a)
: CBase(1,2,3)
{
}
My Execute Class header file
#pragma once
#include "Derived.h"
class CExecute
{
public:
CExecute();
private:
CDerived d;
};
My Execute class source file
#include "Execute.h"
CExecute::CExecute()
{
char rslt = SomeFunction();
d(rslt);
}
Error message
- no default constructor exists for class "CDerived"
- call of an object of a class type without appropriate operator() or conversion functions to pointer-to-function type
- 'CDerived': no appropriate default constructor available
- term does not evaluate to a function taking 1 arguments
Why is this error message when I am choosing to call my parameter'ized constructor ?
The 'marked duplicate' question is about Initializer list. But, I have already used Initializer list for the derived class. So I am aware of the workings.
I have edited my question to make it more clear. Basically how do I invoke a constructor of my choice for a member variable?