Reputation: 23
I'm trying to create an object but apparently it gives some sort of error with the constructor... what? My code that looks like this:
#include <iostream>
#include "Pila.h"
#include "Functions.cpp"
#include <cstring>
using namespace std;
int error = 0;
class Hyogen{
private:
char *kozui;
int p_close;
int p_open;
int err_par, err_op, err_end, err_start;
public:
Hyogen(char *a);
bool Verify();
char *Elaborate();
void Errors();
};
Hyogen::Hyogen(char *a){
kozui = a;
err_par = 0;
err_op = 0;
err_end = 0;
err_start = 0;
p_close = 0;
p_open = 0;
}
bool Hyogen::Verify(){
for(int i=0;i<strlen(kozui);i++){
if(i == strlen(kozui)){
if(error != 0){
cout<<"uwu";
return false;
break;}
else{
cout<<"owo";
return true;}
}
check_parentesis(kozui, p_close, p_open);
if(p_close > p_open || p_open > p_close){
error++;
err_par++;
}
if(i == 0)
if(check_start_various(kozui)){
error++;
err_start++;
}
if(check_operator(kozui)){
if(check_mul_div(kozui))
break;
if(check_doubleop(kozui)){
error++;
err_op++;
}
}
if(i == strlen(kozui))
if(check_end_various(kozui)){
err_end++;
error++;
}
}
}
int main()
{
Hyogen koz;
char *espressione;
espressione = new char[50];
cout<<"Inserisci l'espressione: ";
cin>>espressione;
return 0;
}
The error I'm getting is the following:
main.cpp: In function ‘int main()’:
main.cpp:76:12: error: no matching function for call to ‘Hyogen::Hyogen()’
Hyogen koz;
^~~
main.cpp:20:1: note: candidate: Hyogen::Hyogen(char*)
Hyogen::Hyogen(char *a){
^~~~~~
main.cpp:20:1: note: candidate expects 1 argument, 0 provided
main.cpp:7:7: note: candidate: constexpr Hyogen::Hyogen(const Hyogen&)
class Hyogen{
^~~~~~
main.cpp:7:7: note: candidate expects 1 argument, 0 provided
main.cpp:7:7: note: candidate: constexpr Hyogen::Hyogen(Hyogen&&)
main.cpp:7:7: note: candidate expects 1 argument, 0 provided
What's happening? What do I have to do? It seems like I have to provide an argument when I create the object, but how? (I need to pass "espressione")
Upvotes: 0
Views: 78
Reputation: 28
In the line:
Hyogen koz;
you create object of class with default constructor, which you do not have in the class definition. You have to define default constructor:
Hyogen() { };
Or using in C++11:
Hyogen() = default;
Upvotes: 1
Reputation: 632
#include <iostream>
#include "Pila.h"
#include "Functions.cpp"
#include <cstring>
using namespace std;
int error = 0;
class Hyogen{
private:
char *kozui;
int p_close;
int p_open;
int err_par, err_op, err_end, err_start; public:
Hyogen(char *a);
bool Verify();
char *Elaborate();
void Errors(); };
public:
Hyogen() {}
// ^^^^^^^^^^^
Hyogen(char *a);
bool Verify();
char *Elaborate();
void Errors();
};
as already answered in the comments, you need a default constructor
ClassName ( ) ;
ClassName() = default ;
are other options how to do it
Upvotes: 0