Hi to everybody! I'm writing a program that has to simulate a working system for deliveries of goods to some cities. I get several mistakes from the compiler while temporarly checking the code but they can't point me out the problem good enough.. Therefore I dare to bother you with my question, namely - what's the problem? ;) Here I paste a part of the code. Thank you all in advance!

namespace Error {
          struct Syntax_err {
                 const char* p;
                 Syntax_err (const char *q) {p=q;};
          };
          
          struct File_err {};
}

namespace Truck_Manager {
          
          using namespace Time;
          using namespace Error;
          
          enum Dest { Aachen, Bfeld, Dortm, Duis, Duess, Essen, Kassel, Koeln, Muenstr, WTal };
          enum Stat { Jam, Flat_tyre, Accident, Load_Unload, Driving };
          
          class Truck {
                private:                        
                        unsigned      km_passed;
                        unsigned      km_overall;
                        Stat          curr_stat;
                        Dest          curr_dest;
                        list<Dest>    QDPs[50];              // QDPs == Queued Delivery Places
                        Time_Sim      so_far;                // Time driven so far
                        short         occ_capacity;          // occupied freight capacity
                        bool mutable  dest_success;          // True upon successful destination
                public:                                      // Maintenance Functions
                       Truck (unsigned km_p, unsigned km_all, Dest a=(rand()%8), Time_Sim a, short cap, Stat a=(rand()%8));
                       void Print_WI(Truck T, short num) const;    // current Working Info
                       inline void add_dest(Truck T, Dest new_d);  // adds a new destination for a truck
                       int  add_stat(Truck T, Stat new_s);         // adds event for a given truck
                       int  tmp_save(void);                        // temp save upon dest_success=1
                       void update_queue(Truck T, Dest new_curr_dest, bool a);
                // Output Functions
                       inline unsigned get_km_passed(void) const { return km_passed;};
                       inline unsigned get_km_overall(void) const { return km_overall;};
                       inline Stat get_stat(void) const {return curr_stat;};
                       inline Dest get_dest(void) const {return curr_dest;};
                       //inline void get_tim_e(Time_Sim a) const {Time_Sim::print(Time_Sim a);};  // ?????????
                       inline short get_capacity(void) const {return occ_capacity;};
          };
}
void Truck_Manager::Truck::Print_WI(Truck T, short num) const {
     cout << "\n\n\n\n\n" << " Working info for Truck " << num << ": ";
     cout << "\n Km overall: " << get_km_overall() << "\n Status: " << get_stat();
     cout << "\n Current Destitantion: " << get_dest() << "\n Driving time: ";// << get_tim_e(so_far);
     cout << "\n Occupied freights: " << get_capacity() << " (" << (8-get_capacity()) << " free)\n";
     
     system("PAUSE");
}
     
     
void Truck_Manager::Truck::update_queue(Truck T, Dest new_curr_dest, bool a) {
     typedef list<Dest>::iterator LI;
     if(!tmp_save()) throw File_err;
     curr_dest = new_curr_dest;
     
     for(LI i=QDPs.begin(); i<QDPs.end(); ++i)
             QDPs.push_front(*i);
     a = true;
}
     
              
inline void Truck_Manager::Truck::add_dest(Truck T, Dest new_d) {
    QDPs.push_back(new_d);
}

int Truck_Manager::Truck::add_stat(Truck T, Stat new_s) {
         curr_stat = new_s;
}

What errors are you getting? Can you post them as well, please?

Sure, I'm sorry. The line numbers will be wrong, though, because there is code missing (everything is in one file only for now, so I don't loose the connection (I'm quite new to C++)). All the mistakes are in the membering functions and they are in the order given in the code above. So are the errors. The errors are:

Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\My Projects\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\My Projects\Makefile.win" all
g++.exe -c Route_Manager.cpp -o Route_Manager.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include"

Route_Manager.cpp: In member function `void Truck_Manager::Truck::update_queue(Truck_Manager::Truck, Truck_Manager::Dest, bool)':
Route_Manager.cpp:73: error: expected primary-expression before ';' token

Route_Manager.cpp:76: error: request for member `begin' in `((Truck_Manager::Truck*)this)->Truck_Manager::Truck::QDPs', which is of non-class type `std::list<Truck_Manager::Dest, std::allocator<Truck_Manager::Dest> >[50]'
Route_Manager.cpp:76: error: request for member `end' in `((Truck_Manager::Truck*)this)->Truck_Manager::Truck::QDPs', which is of non-class type `std::list<Truck_Manager::Dest, std::allocator<Truck_Manager::Dest> >[50]'
Route_Manager.cpp:77: error: request for member `push_front' in `((Truck_Manager::Truck*)this)->Truck_Manager::Truck::QDPs', which is of non-class type `std::list<Truck_Manager::Dest, std::allocator<Truck_Manager::Dest> >[50]'

Route_Manager.cpp: In member function `void Truck_Manager::Truck::add_dest(Truck_Manager::Truck, Truck_Manager::Dest)':
Route_Manager.cpp:83: error: request for member `push_back' in `((Truck_Manager::Truck*)this)->Truck_Manager::Truck::QDPs', which is of non-class type `std::list<Truck_Manager::Dest, std::allocator<Truck_Manager::Dest> >[50]'

make.exe: *** [Route_Manager.o] Error 1

Execution terminated

This is the compiler log. The OS is WinXP Proffessional (if this matters in the current case).

Thanks!

<< moderator edit: smilies disabled >>

All the smiles are because of the Dest enumeration, not some pervert joke of mine. : is simply followed by the capital 'D' from the enumaration's name. Sorry for the inconvenience!

You have quite a few errors. This at least compiles:

namespace Error {
  struct Syntax_err {
    const char* p;
    Syntax_err (const char *q) {p=q;};
  };

  struct File_err {};
}

namespace Truck_Manager {
  using namespace Time;
  using namespace Error;

  enum Dest { Aachen, Bfeld, Dortm, Duis, Duess, Essen, Kassel, Koeln, Muenstr, WTal };
  enum Stat { Jam, Flat_tyre, Accident, Load_Unload, Driving };

  Dest rand_Dest() { return (Dest)( rand() % 10 ); }
  Stat rand_Stat() { return (Stat)( rand() % 5 ); }

  class Truck {
  private:                        
    unsigned      km_passed;
    unsigned      km_overall;
    Stat          curr_stat;
    Dest          curr_dest;
    list<Dest>    QDPs;                  // QDPs == Queued Delivery Places
    Time_Sim      so_far;                // Time driven so far
    short         occ_capacity;          // occupied freight capacity
    bool mutable  dest_success;          // True upon successful destination
  public:                                      // Maintenance Functions
    Truck (unsigned km_p, unsigned km_all, Time_Sim b, short cap, Dest a=rand_Dest(), Stat c=rand_Stat());
    void Print_WI(Truck T, short num) const;    // current Working Info
    inline void add_dest(Truck T, Dest new_d);  // adds a new destination for a truck
    void  add_stat(Truck T, Stat new_s);         // adds event for a given truck
    int  tmp_save(void);                        // temp save upon dest_success=1
    void update_queue(Truck T, Dest new_curr_dest, bool a);
    // Output Functions
    inline unsigned get_km_passed(void) const { return km_passed;};
    inline unsigned get_km_overall(void) const { return km_overall;};
    inline Stat get_stat(void) const {return curr_stat;};
    inline Dest get_dest(void) const {return curr_dest;};
    //inline void get_tim_e(Time_Sim a) const {Time_Sim::print(Time_Sim a);};  // ?????????
    inline short get_capacity(void) const {return occ_capacity;};
  };
}

void Truck_Manager::Truck::Print_WI(Truck T, short num) const {
  cout << "\n\n\n\n\n" << " Working info for Truck " << num << ": ";
  cout << "\n Km overall: " << get_km_overall() << "\n Status: " << get_stat();
  cout << "\n Current Destitantion: " << get_dest() << "\n Driving time: ";// << get_tim_e(so_far);
  cout << "\n Occupied freights: " << get_capacity() << " (" << (8-get_capacity()) << " free)\n";

  system("PAUSE");
}

void Truck_Manager::Truck::update_queue(Truck T, Dest new_curr_dest, bool a) {
  typedef list<Dest>::iterator LI;
  if(!tmp_save()) throw File_err();
  curr_dest = new_curr_dest;

  for(LI i=QDPs.begin(); i!=QDPs.end(); ++i)
    QDPs.push_front(*i);
  a = true;
}

inline void Truck_Manager::Truck::add_dest(Truck T, Dest new_d) {
  QDPs.push_back(new_d);
}

inline void Truck_Manager::Truck::add_stat(Truck T, Stat new_s) {
  curr_stat = new_s;
}

Let's go over some of the changes I made:

>Truck (unsigned km_p, unsigned km_all, Dest a=(rand()%8),
>Time_Sim a, short cap, Stat a=(rand()%8));
Unlike in C, integral values are not implicitly convertable to an enumerated type. You need to cast to Dest and Stat. But, the modulus for rand() is wrong because Dest has 10 values and Stat has 5, yet you fit rand() into the range of 8 for both. That has disaster written all over it. So I wrote two functions that fit the random number into the correct range, then cast to the right type.

>if(!tmp_save()) throw File_err;
When you throw an object of class or structure type, you need to remember that you'er calling the constructor. I added parens.

>for(LI i=QDPs.begin(); i<QDPs.end(); ++i)
You seem to think that QDPs (not the best choice of names) is a single list rather than an array of lists as you declared it. I changed the array to a single list.

>int Truck_Manager::Truck::add_stat(Truck T, Stat new_s) {
You say you'll return int, but don't. I changed this to return void.

However, since the code is incomplete, I can't guarantee that some of those changes will fix all of your problems. But there were some legitimate problems that your error list didn't include.

First - thanks for the answer!

The rand()%8 expressions were there to remind me of the idea that I had, because I wasn't sure if it is better to simply imput the different (random) cases, because the program is for 5 trucks only or if I should randomize the choice, so it is more flexible for different number of trucks. The second is the better choice, but since I'm not too experienced in C++ i decided to leave this choice to be made by the technical issues that appear from the coding requirements and simply to take the option that causes less problems so I'm sure that I'll be ready by the deadline I have. I didn't know that integral values should be explicitly converted to enumerations, though, so.. thanks once again!

The other stuff is more or less little mistakes and I have probably skipped them because I look at this code and constantly try new stuff from the books I am reading and I miss a bit the clear view, i.e. it's a little mess in my head at the moment, but I don't have problems understanding you.

Anyway the code is running without mistakes now and I can go on without having the feeling that I am doing everything wrong :-)

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.