This is my last question over my current running project. For some reason, when i call my object in my main program it gives me errors. If I try to call it as:

Checkout_Simulation sim_obj;

Then I get errors:

Checkout_Simulation.cpp:16: error: missing template arguments before ‘sim_obj’
Checkout_Simulation.cpp:16: error: expected `;' before ‘sim_obj’
Checkout_Simulation.cpp:31: error: ‘sim_obj’ was not declared in this scope

I know this is due to the fact that my program is a template class. Therefore I try:

Checkout_Simulation<int> sim_obj;

I get list of errors like:

Checkout_Simulation.cpp:17:   instantiated from here
Checkout_Simulation.h:27: error: cannot convert ‘const char*’ to ‘Passenger<int>*’ in initializat                                                                ion
Checkout_Simulation.h:27: error: cannot convert ‘const char*’ to ‘Passenger<int>*’ in initializat                                                                ion
Checkout_Simulation.h:27: error: cannot convert ‘const char*’ to ‘Passenger<int>*’ in initializat                                                                ion
Checkout_Simulation.h:27: error: cannot convert ‘const char*’ to ‘Passenger<int>*’ in initializat                                                                ion
Checkout_Simulation.h: In member function ‘void Checkout_Simulation<NODETYPE>::enter_information(                                                                ) [with NODETYPE = int]’:
Checkout_Simulation.cpp:31:   instantiated from here
Checkout_Simulation.h:180: error: request for member ‘set_arrivalRate’ in ‘((Checkout_Simulation<                                                                int>*)this)->Checkout_Simulation<int>::super_express’, which is of non-class type ‘Passenger<int>                                                                *’
Checkout_Simulation.h:183: error: request for member ‘set_arrivalRate’ in ‘((Checkout_Simulation<                                                                int>*)this)->Checkout_Simulation<int>::express_line1’, which is of non-class type ‘Passenger<int>                                                                *’
Checkout_Simulation.h:186: error: request for member ‘set_arrivalRate’ in ‘((Checkout_Simulation<                                                                int>*)this)->Checkout_Simulation<int>::express_line2’, which is of non-class type ‘Passenger<int>                                                                *’
Checkout_Simulation.h:189: error: request for member ‘set_arrivalRate’ in ‘((Checkout_Simulation<                                                                int>*)this)->Checkout_Simulation<int>::regular_lines’, which is of non-class type ‘Passenger<int>                                                                *’
Checkout_Simulation.h: In member function ‘void  Checkout_Simulation<NODETYPE>::run_sim() [with NO                                                                DETYPE = int]’:
Checkout_Simulation.cpp:32:   instantiated from here
Checkout_Simulation.h:64: error: request for member ‘check_new_arrival’ in ‘((Checkout_Simulation                                                                <int>*)this)->Checkout_Simulation<int>::super_express’, which is of non-class type ‘Passenger<int                                                                >*’
Checkout_Simulation.h:70: error: request for member ‘check_new_arrival’ in ‘((Checkout_Simulation                                                                <int>*)this)->Checkout_Simulation<int>::express_line1’, which is of non-class type ‘Passenger<int                                                                >*’
Checkout_Simulation.h:71: error: request for member ‘check_new_arrival’ in ‘((Checkout_Simulation                                                                <int>*)this)->Checkout_Simulation<int>::express_line2’, which is of non-class type ‘Passenger<int                                                                >*’

and etc.

I also tried the following as well:

    //LinkedList<int> *sim_obj = new LinkedList<int>();
    //Checkout_Simulation() *sim_obj;
    //Checkout_Simulation<int> *sim_obj = new Checkout_Simulation<int>();

    //Checkout_Simulation sim_obj = new Checkout_Simulation<int>();

    //Checkout_Simulation<int> *sim_obj<int>();

    //Checkout_Simulation<int> *sim_obj;
    //Checkout_Simulation<int> *sim_obj = new Checkout_Simulation();
    //Checkout_Simulation<int> *sim_obj = new Checkout_Simulation<int>();

I have been collaborating over why these calls are not working and have hit a brick wall.

Below is my current project. All of my files show no compiling errors. Only my Checkout_Simulation.cpp is my issue currently.

Checkout_Simulation.cpp

#include "Checkout_Simulation.h"
#include "Random.h"
#include <iostream>
#include <string>
#include <cctype>
#include "LinkedList.h"
#include <queue>
#include "Passenger.h"
#include "Queue.h"


using namespace std;

int main() {

   // Checkout_Simulation sim_obj;
    Checkout_Simulation<int> sim_obj;
    //LinkedList<int> *sim_obj = new LinkedList<int>();
    //Checkout_Simulation() *sim_obj;
    //Checkout_Simulation<int> *sim_obj = new Checkout_Simulation<int>();

    //Checkout_Simulation sim_obj = new Checkout_Simulation<int>();

    //Checkout_Simulation<int> *sim_obj<int>();

    //Checkout_Simulation<int> *sim_obj;
    //Checkout_Simulation<int> *sim_obj = new Checkout_Simulation();
    //Checkout_Simulation<int> *sim_obj = new Checkout_Simulation<int>();


    sim_obj.enter_information();
    sim_obj.run_sim();
    sim_obj.show_information();


    return 0;
}

Checkout_Simulation.h

#ifndef CHECKOUT_SIMULATION_H
#define CHECKOUT_SIMULATION_H
#include "Queue.h"
#include "Random.h"
#include <iostream>
#include <string>
#include <cctype>
#include <queue>
#include "Passenger_Queue.h"

using namespace std;
//Global random generator from Random.h
Random simulation_obj;
Random item_obj;

template <typename NODETYPE>
class Checkout_Simulation{


public:

    int items;

Checkout_Simulation() : super_express("Super Express Counter 01"),
            express_line1("Express Line Counter 01"),
            express_line2("Express Line Counter 02"),
            regular_lines("Regular Line Counter"), 
            clock_time(0), finish_time(0) {}

void run_sim();
void show_information();
void enter_information();

private:

void start_checkout();
Passenger<NODETYPE> *super_express;
Passenger<NODETYPE> *express_line1;
Passenger<NODETYPE> *express_line2;
Passenger<NODETYPE> *regular_lines;

int super_express_max;
int processTime_max;
int total_time;
bool display_all;
int clock_time;
int finish_time;
int numberRegularLines;
// number of super_express served since last regular customer
int super_express_since_regular;




};

template <typename NODETYPE>
void Checkout_Simulation<NODETYPE> :: run_sim() {

    for(clock_time = 0; clock_time <total_time; clock_time++){

item_obj.item_purchase(items);

    if (items < 15) {
      super_express.check_new_arrival(clock_time, display_all, items);
// number = the value
  //super_express.number = number;
}
else if (items >15 && items <=20){

  express_line1.check_new_arrival(clock_time, display_all, items);
  express_line2.check_new_arrival(clock_time, display_all, items);
}
else {

 //Create the number of regular lines the user entered (1-10)
 Queue<Passenger<NODETYPE> *> regular_lines;
 for (int i=0; i< numberRegularLines; i++){
    regular_lines.push(new Passenger<NODETYPE>);
    regular_lines.check_new_arrival(clock_time, display_all, items);
     }
}  //end else



if (clock_time >= finish_time){
            start_checkout();
      }

    }//end for loop
}

template <typename NODETYPE>
void Checkout_Simulation<NODETYPE> :: start_checkout() {

/* if express lines are both empty and regular, and super_express_since_regular less 
then super_expresses max hold, then update since_regular and super_express */
    if( (!express_line1.empty() || !express_line2.empty())
            && ( (super_express_since_regular <= super_express_max) ||
            regular_lines.empty() )){


            super_express_since_regular++;
            finish_time = super_express.update(clock_time, display_all);

    }//end if

//if the regular line isn't empty, super_express_since_regular = 0 and update regular
    else if (!regular_lines.empty()){

            super_express_since_regular = 0;
            finish_time = regular_lines.update(clock_time, display_all);

    }//end else if



// if regular_line is not empty and 
//else if (!regular_line.empty() && super_express

else if (display_all){

            cout << "Current time is " << clock_time <<": current counter is empty\n";

    //}// end else if

}
}

template <typename NODETYPE>
void Checkout_Simulation<NODETYPE> :: show_information(){

    cout << "\n The number of regular customers served was "
            << regular_lines.get_servedTotal() << endl;
    double average_wait = double(regular_lines.get_totalWait())/
                                      double(regular_lines.get_servedTotal());
    cout <<", with average waiting time of " << average_wait << endl;


    cout <<"The number of express customers served in Express Line 01 was "
            << express_line1.get_servedTotal() <<endl;
    average_wait = double(express_line1.get_totalWait())/
                            double(express_line1.get_servedTotal());
    cout <<", with average waiting time of " << average_wait <<endl;


    cout <<"The number of express customers served in Express Line 02 was "
            << express_line2.get_servedTotal() <<endl;
    average_wait = double(express_line2.get_totalWait())/
                            double(express_line2.get_servedTotal());
    cout <<", with average waiting time of " << average_wait <<endl;


    cout <<"The number of super express customers served was "
            << super_express.get_servedTotal() <<endl;
    average_wait = double(super_express.get_totalWait())/
                            double(super_express.get_servedTotal());
    cout <<", with average waiting time of " << average_wait <<endl;


    cout <<"Overall waiting time till all customers are helped is: "<<endl;


    cout <<"Max length of super express line was: "<<endl;

    cout <<"Average free time of super express line was:" <<endl;


}


template <typename NODETYPE>
void Checkout_Simulation<NODETYPE> :: enter_information() {

    double input;
    int max_processTime;
    string response;

    cout <<"Expected number of super_express customers per hour: ";
    cin >> input;
    super_express.set_arrivalRate(input/ 60.0);
    cout <<"Expected number of express customers in Express Line 01 per hour: ";
    cin >> input;
    express_line1.set_arrivalRate(input/60.0);
    cout <<"Expected number of express customers in Express Line 02 per hour: ";
    cin >> input;
    express_line2.set_arrivalRate(input/60.0);
    cout <<"Expected number of regular customers per hour: ";
    cin >> input;
    regular_lines.set_arrivalRate(input/60.0);

cout <<"How many regular lines does the grocery store provide? (1-10) : ";
cin >>numberRegularLines;
    cout <<"Enter maximum number of super express customers served between express and regular customers ";
    cin >> max_processTime;
    cout <<"Enter total time in minutes for simulation: ";
    cin >> total_time;
    cout <<"Display simulation at a minute interval (Y or N) ";
    cin >>response;

    display_all = toupper (response[0]) == 'Y';
}  

#endif

Passenger_Queue.h

#ifndef PASSENGER_QUEUE_H
#define PASSENGER_QUEUE_H
#include <string>
#include <queue>
#include "Passenger.h"
#include "Queue.h"
#include "Random.h"

template <typename NODETYPE>
class Passenger_Queue {

public:

Passenger_Queue(string name);
int get_servedTotal() const;
int get_totalWait() const;
string get_queue() const;
void set_arrivalRate(double new_rate);
int isEmpty() const;
void check_new_arrival(int, bool, int);
int update(int, bool);
int getSize();

private:

 LinkedList<NODETYPE> *current_queue;
     int count_total;
     int total_wait;
     double initial_rate;
 string QueueName;
};

template <typename NODETYPE>
  Passenger_Queue<NODETYPE> :: Passenger_Queue(string name) : count_total(0), total_wait(0),
  QueueName(name) {}

template <typename NODETYPE>
int Passenger_Queue<NODETYPE> :: get_servedTotal() const{
    return count_total;
}

template <typename NODETYPE>
int Passenger_Queue<NODETYPE> :: get_totalWait() const {
    return total_wait;
}

//set arrival
template <typename NODETYPE>
void Passenger_Queue<NODETYPE> :: set_arrivalRate(double new_rate) {

      initial_rate = new_rate;

}

template <typename NODETYPE>
int Passenger_Queue<NODETYPE> :: isEmpty() const{
          // return true if the queue object is empty
    return current_queue -> isEmpty();
    }//end isEmpty method


template <typename NODETYPE>
int Passenger_Queue<NODETYPE> :: getSize(){
            return current_queue -> getSize();

    }

template <typename NODETYPE>
string Passenger_Queue<NODETYPE> :: get_queue() const {
      return QueueName;
}

//See nitial_rate = new_rate;
template <typename NODETYPE>
void Passenger_Queue<NODETYPE> :: check_new_arrival(int clock, bool display_all, int items){

    if (simulation_obj.next_double() < initial_rate) {

            current_queue.push(Passenger<NODETYPE>(clock, items));

      if(display_all) {
            cout <<"Time is " << clock << ": " << QueueName
                    << " arrival, new queue size is "
                    << current_queue.getSize() <<endl;
      }

    }
}

template <typename NODETYPE>
int Passenger_Queue<NODETYPE> :: update(int clock, bool display_all) {

    Passenger<NODETYPE> *next_customer = current_queue.pop();
    //current_queue.pop();

    int time = next_customer.get_initialTime();
    int wait = clock - time;

    total_wait += wait;
    count_total++;

    if(display_all) {

      cout <<"Time is " << clock << ": Serving " << QueueName
      << " with time stamp at " << time << endl;
    }

    return clock + next_customer.get_processTime();
}


#endif

Passenger.h

#ifndef PASSENGER_H
#define PASSENGER_H
#include <iostream>
#include "Random.h"

//Use object from Checkout_Simulation.cpp
extern Random simulation_obj;
extern Random item_obj;

using namespace std;

template <typename NODETYPE>
class Passenger {

public:


Passenger(int, int);
int get_initalTime();
int get_processTime();
//  int get_id();
static void set_max_processTime(int max_processTime);

    private:
     //int id;
     int processTime;
     int initalTime;
 int initalItems;
     static int max_processTimeInterval;
     //sequence for passengers
     //static int id_number;


};

 //Get time Passenger arrived
template <typename NODETYPE>
int Passenger<NODETYPE> :: get_initalTime() {

  return initalTime;

 }
 //Get process time of passenger
template <typename NODETYPE>
int Passenger<NODETYPE> :: get_processTime() {

  return processTime;

}

template <typename NODETYPE>
void Passenger<NODETYPE> :: set_max_processTime(int max_processTime) {

  max_processTimeInterval = max_processTime;

}

// Makes a new customer with their time that they arrived
template <typename NODETYPE>
Passenger<NODETYPE> :: Passenger(int inital, int items){
    //initalTime is from Passenger.h
    initalTime = inital;
initalItems = items;
    //processTime is from Passenger.h
    processTime = 1 + simulation_obj.next_int(max_processTimeInterval);

}

//Max time to process passenger
template <typename NODETYPE>
int Passenger<NODETYPE> :: max_processTimeInterval;



#endif

Queue.h

#ifndef QUEUE_H
#define QUEUE_H
#include <string>
#include <queue>
#include <cstddef>
#include <algorithm>
#include <list>
#include <sstream>
#include "Passenger.h"
#include "Random.h"
#include <iostream>
#include "LinkedList.h"

extern Random simulation_obj;

using namespace std;

template <typename NODETYPE>
class Queue {

public:

Queue();
~Queue();
int isEmpty() const;
int getSize();
//void check_new_arrival(int, bool);
//void set_arrivalRate(double new_rate);
//int get_totalWait() const;
//int get_servedTotal() const;
void push(const NODETYPE& item);
void pop();
//int update(int, bool);
//string get_queue() const;
private:
LinkedList<NODETYPE> *current_queue;
int size;

};
template <typename NODETYPE>
Queue<NODETYPE> :: Queue() {
            // Create the queue object here
    current_queue = new LinkedList<NODETYPE>();
    }//end constructor


template <typename NODETYPE>
Queue<NODETYPE> :: ~Queue() {

      if (!current_queue -> isEmpty()){

            delete current_queue;
            cout <<" Deleting resources \n";
      }
    }

template <typename NODETYPE>
void Queue<NODETYPE> :: pop() {

current_queue -> removeFromHead();

}
template <typename NODETYPE>
void Queue<NODETYPE> :: push(const NODETYPE& item){

current_queue -> insertAtHead(item);

}

template <typename NODETYPE>
int Queue<NODETYPE> :: isEmpty() const{
          // return true if the queue object is empty
    return current_queue -> isEmpty();
    }//end isEmpty method

template <typename NODETYPE>
int Queue<NODETYPE> :: getSize(){
            return current_queue -> getSize();

    }

#endif

Other files are: Random.h ListNode.h LinkedList.h

Checkout_Simulation.h:27: error: cannot convert 'const char*' to 'Passenger<int>*' in initialization

This is because you're trying to assign a char* to an object of type Passenger<NODETYPE>* in your initialisation list, here: Checkout_Simulation() : super_express("Super Express Counter 01"),

See there? super_express is a Passenger<NODETYPE>* object, and you're basically trying to do this:

super_express = "Super Express Counter 01"

That makes no sense. If super_express is meant to be a string, why have you made it a Passenger<NODETYPE>*? If it's meant to be a Passenger<NODETYPE>*, why are you trying to make it equal to a string?

Similarly for all those identical errors.

Why is your Passenger type a template? It doesn't use the templated type anywhere.

Edited 1 Year Ago by Moschops

This article has been dead for over six months. Start a new discussion instead.