简体   繁体   中英

OOP, Constructor not working

I am trying to call constructor but it is not working. Code is something like this:

// Event.h

class Event
{
  private:
    int Time;
    int Date;
  public:
    Event();
    Event(int t, int d)
}

// Event.cpp

Event::Event(){}

Event::Event(int time, int date){
Time=time;
Date=date;
}

//Now in another .cpp file I am trying to call constructor something like this:

Event eve;
eve(inputTime,inputDate); // inputTime and inputDate are inputs 4m user.
//Error is:  no match for call to â(Event) (Time&, Date&)â

Any suggestions..............

This

eve(inputTime,inputDate); 

requires that your Event class have an operator()(something, somethingElse) , which it doesn't have. something and somethingElse would correspond to the types of inputTime and inputDate respectively, which are not specified in your question.

Presumably you want to construct an Event using the two argument constructor, which you can do like this:

Event eve(inputTime,inputDate);

Since the error also mentions types Time and Date , you probably need to add a constructor that takes const references to those types, unless they can be implicitly converted to int .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM