0

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")

3
  • See this question: no default constructor exists for class Commented Apr 11, 2018 at 21:00
  • But to fix your issue, move Hyogen koz; to after where you get the input and change to Hyogen koz(espressione); Commented Apr 11, 2018 at 21:02
  • It still gives an error, I tried :/ Edit: It worked, thank you so much! Commented Apr 11, 2018 at 21:03

3 Answers 3

1

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; 
Sign up to request clarification or add additional context in comments.

Comments

0
int main()
{
    //Hyogen koz;        Move this
    char *espressione;
    espressione = new char[50];
    cout<<"Inserisci l'espressione: ";
    cin>>espressione;
    Hyogen koz(espressione);    // To here and add parameter
    return 0;
}

DEMO (with some extraneous code removed).

Comments

0
#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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.