Hey all, it's my first time working with templates and I'm running in to some weird stuff. On top of that, I think my compiler is screwing with me because it's giving output for cout statements I've removed.
I'm making a queue-type program that keeps track of tasks and figures out an order to do them in. I have a normal Task class and a templated Scheduler class. Inside the Scheduler class I'm trying to access parts of a Task but it either prints an address or says it cant find the part.
class Task{
string priority_;
int arrival_;
int duration_;
string info_;
public:
Task(); //Default constructor
Task(string, int, string); //Constructor for tasks in main
friend ostream& operator<<(ostream&, const Task &); //Allows to print Task
friendclass Scheduler <Task>; //Gives friend status to scheduler class.
};
task.cpp
1 2 3 4 5 6 7 8 9 10 11
Task::Task(){ //Default construtor
priority_ = "empty";
duration_ = 0;
info_ = "";
}
Task::Task(string p, int d, string i){ //Constructor for given info
p = priority_;
d = duration_;
i = info_;
}
#ifndef SCHEDULER_H
#define SCHEDULER_H
template<typename T> //In this case, T is a Task class.
class Scheduler;
template <typename T> //In this case, T is a Task class.
class Scheduler{
private:
deque<T> low_; //Low priority queue
deque<T> high_; //High priority queue
int time_; //Increases based on time it took to complete task
int late_; //Amount of time Task can be in queue before considered late
public:
Scheduler();
Scheduler(int, int);
void schedule(T &);
};
template<typename T>
Scheduler<T>::Scheduler(){ //Default scheduler constructor
time_ = 0;
late_ = 0;
}
template<typename T>
Scheduler<T>::Scheduler(int time, int late){ //Scheduler constructor
time_ = time;
late_ = late;
}
template<typename T>
void Scheduler<T>::schedule(T &task){ //ISSUES IN HERE SOMEWHERE
cout << this->time_ << endl; //Correctly prints the 0 & 50, though output continues on future runs even if these couts are deleted, which is REALLY weird to me.
cout << this->late_ << endl;
cout << task.duration_; //Duration for the task will not print, gives me a random address or fails. Should be printing a 25 as declared in main earlier.
}
#endif /* SCHEDULER_H */
Any suggestions/help/pointers greatly appreciated! Thanks in advance guys/gals.