I'm a bit new to Object Oriented Programming in C++.
I have created this class "Demo".
Demo.h :
#pragma once
#include<iostream>
using namespace std;
class Demo
{
public :
Demo(int a);
~Demo();
};
Demo.cpp :
#include "Demo.h"
Demo::Demo(int a)
{
cout << a;
}
Demo::~Demo()
{
}
Now if I pass an integer value while calling the constructor ...... it works properly. Like this :
#include <iostream>
#include<vector>
#include "Demo.h"
using namespace std;
int main()
{
Demo(1);
}
But when I pass an integer variable as a parameter like this :
#include <iostream>
#include<vector>
#include "Demo.h"
using namespace std;
int main()
{
int a = 1;
Demo(a);
}
It doesn't work and gives an error and an exception :
Error (active) E0291 no default constructor exists for class "Demo"
Warning C26444 Avoid unnamed objects with custom construction and destruction
I am curious about why am I getting this error and how can I fix it.
Thanks in advance for the halp.