0

Here unsigned long EVTime::seconds() method is conflicting with ptime p(d,seconds(s));. If I change ptime seconds(s) to minutes/hours then it works fine.

If i change that seconds(s) to minutes(s) or hours(s) then only it will work. I am new to C++, anyone please help to resolve this conflict.

evt.cpp:

unsigned long EVTime::seconds()
{
  ptime t(date(1901,Jan,1),time_duration(0,0,0));
  time_duration td = utcdatetime - t;
  return (unsigned long)td.total_seconds();
}

EVTime::EVTime(unsigned long s)
{
  date d(1901,1,1);
  ptime p(d,seconds(s));
  utcdatetime=p;
}

evt.h:

class EVTime
{
public:
  EVTime(unsigned long s);
  unsigned long seconds();
  ptime utcdatetime;
};

main.cpp:

int main()
{
  EVTime t(222l);
  cout<<"seconds since 1901: "<<t.seconds()<<endl;
}

Error code:

evtime.cpp: In constructor ‘EVTime::EVTime(long unsigned int)’:
evtime.cpp:35: error: no matching function for call to ‘EVTime::seconds(long 
unsigned int&)’
evtime.cpp:14: note: candidates are: long unsigned int EVTime::seconds()
sunil
  • 19
  • 7
  • 1
    It looks as though your function `seconds()` takes no parameters, but you send it `s` when you call it: `ptime p(d,seconds(s));` (I presume the *s are for emphasis?) – doctorlove Aug 22 '18 at 07:56
  • Please remove the emphasis asterisks, they disrupt code and don't really contribute anything to the discussion. If you want to emphasize something in your code, just use a comment. Anyway, I think your problem is that you are relying on `using namespace`. This is a mistake. If you need to use `boost::posix_time::seconds`, spell it `boost::posix_time::seconds` every time, or use a namespace alias. – n. m. could be an AI Aug 22 '18 at 08:03
  • Thanks, "boost::posix_time::seconds" this line works for me – sunil Aug 22 '18 at 09:20

1 Answers1

0

Your function seconds() takes no parameters, but you send it s when you call it: ptime p(d,seconds(s));

This causes the error "no matching function for call to EVTime::seconds(long unsigned int&)", since you don't have a matching function.

Either call ptime p(d,seconds()); or change the seconds function signature to take the parameter and do something with it.

doctorlove
  • 18,872
  • 2
  • 46
  • 62