Need to slove c++ error as soon as possible
Dec 8, 2017 at 4:52pm UTC
Hello ,
I need to create a program to simulate waiting time, and I am following à tutorial on data structure c++ book, in the book they have only made function declaration and I need to put the .cpp file; my problem is that I got the error below :
invalid conversion from 'TimerType*' to 'int'
TimerType.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#ifndef TIMERTYPE_H
#define TIMERTYPE_H
class TimerType
{
public :
/*--------Constructor -----------*/
TimerType();
/*--------Sets count too value-----*/
void SetTimer(int );
/*---------Increments count -------*/
void Increment();
/*---------Decrements count -------*/
void Decrement();
/*---------Returns count -------*/
int TimeIs() const ;
virtual ~TimerType();
private :
int count;
};
#endif // TIMERTYPE_H
TimerType.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include "TimerType.h"
TimerType::TimerType()
{
count =0;
}
void TimerType::SetTimer(int value)
{
count = value;
}
void TimerType::Increment()
{
count++;
}
void TimerType::Decrement()
{
count--;
}
int TimerType::TimeIs() const
{
return count;
}
TimerType::~TimerType()
{
//dtor
}
JobType.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
#ifndef JOBTYPE_H
#define JOBTYPE_H
#include "TimerType.h"
class JobType
{
public :
/*--------Constructor -----------*/
JobType();
/*--------Increment WaitTime -----*/
void IncrementWaitTime();
/*--------Returns the value of waitTime -----*/
int WaitTimeIs();
/*--------Destructor ------------*/
virtual ~JobType();
private :
TimerType waitTime;
};
#endif // JOBTYPE_H
JobType.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "JobType.h"
JobType::JobType()
{
//ctor
}
void JobType::IncrementWaitTime()
{
}
int JobType::WaitTimeIs()
{
return waitTime;
}
JobType::~JobType()
{
//dtor
}
They gave the .h and I have to make the . cpp
they have as comment to return the waitTime and thet make it as object I am little bit confused
Could someone please help me
Thank you
Last edited on Dec 8, 2017 at 4:58pm UTC
Dec 8, 2017 at 5:10pm UTC
jobtype.h line 24: waitTime is a TimerType.
jobtype.cpp line 14: You're saying WaitTimeIs() returns an int, however waitTime is a TimerType and you have not provided a conversion from a TimerType to an int.
Easiest fix is to change jobtype.cpp line 16 to:
return waitTime.TimeIs();
A better fix would be to change WaitTimeIs() to return a TimerType.
Dec 8, 2017 at 5:13pm UTC
Thank you a lot now I understand well, and it is okey now
Thanks
Topic archived. No new replies allowed.