c++ - Trouble figuring out what's wrong with this code on Linux -


i'm having trouble figuring out why code not working on linux. i'm getting errors shared_ptrs like: (partial list)

roject.cpp:21: error: iso c++ forbids declaration of 'shared_ptr' no type project.cpp:21: error: expected ';' before '<' token project.cpp:22: error: iso c++ forbids declaration of 'shared_ptr' no type project.cpp:22: error: expected ';' before '<' token project.cpp:23: error: iso c++ forbids declaration of 'shared_ptr' no type project.cpp:23: error: expected ';' before '<' token project.cpp:30: error: iso c++ forbids declaration of 'shared_ptr' no type project.cpp:30: error: expected ';' before '<' token project.cpp:37: error: iso c++ forbids declaration of 'shared_ptr' no type project.cpp:37: error: expected ';' before '<' token project.cpp:82: error: 'shared_ptr' has not been declared project.cpp:82: error: expected ',' or '...' before '<' token project.cpp:153: error: 'shared_ptr' has not been declared project.cpp:153: error: expected ',' or '...' before '<' token project.cpp: in member function 'void device_table::addcore(int)': project.cpp:86: error: 'process' not declared in scope project.cpp:88: error: 'struct device_item' has no member named 'process' project.cpp:89: error: 'currenttime' not declared in scope project.cpp:92: error: 'struct device_item' has no member named 'process' project.cpp:98: error: 'struct device_item' has no member named 'process' project.cpp:104: error: 'struct device_item' has no member named 'process' project.cpp:110: error: 'struct device_item' has no member named 'process' project.cpp:124: error: 'process_state' not class or namespace project.cpp:130: error: 'process_state' not class or namespace project.cpp:137: error: 'struct device_item' has no member named 'process' project.cpp:137: error: 'process' not declared in scope project.cpp:138: error: 'currenttime' not declared in scope project.cpp:140: error: 'process_state' not class or namespace project.cpp: in member function 'void device_table::adddisk(int)': project.cpp:156: error: 'struct device_item' has no member named 'process' project.cpp:156: error: 'disk' not declared in scope project.cpp:157: error: 'currenttime' not declared in scope project.cpp:167: error: 'process_state' not class or namespace project.cpp: in member function 'void device_table::checkcoreanddisk(int)': 

here's code. realized shouldn't have used vectors. there's next time.

#include <iostream> #include <string> #include <fstream> #include <vector> #include <memory> #include <algorithm> #include <queue>  using namespace std;  enum process_state { p_none, ready, running, waiting }; enum event_component { e_none, start, core, tty, disk };  struct data_entry {     string text;     int time; };  struct process_entry {     int process;     shared_ptr<data_entry> * datastart;     shared_ptr<data_entry> * dataend;     shared_ptr<data_entry> * datacurrent;     process_state state;     int deadline;     int totaltime; };  struct event_entry {     shared_ptr<process_entry> * process;     int time;     event_component component;  };  struct device_item {     shared_ptr<process_entry> * process;     int finishtime;      int starttime;     int endtime; };  class device_table {     device_item * core1;     device_item * core2;     device_item * core3;     device_item * core4;     device_item * disk1;      std::queue<device_item*> iq;     std::queue<device_item*> rq;     std::queue<device_item*> diskq;      int completedreal;     int completedinter;     int completeddisk;      double durationdisk;     int coreutilization[4];     int diskutilization;  public:     device_table()     {         core1 = null;         core2 = null;         core3 = null;         core4 = null;         disk1 = null;         completedreal = 0;         completedinter = 0;         completeddisk = 0;         durationdisk = 0;         diskutilization = 0;          coreutilization[0] = 0;         coreutilization[1] = 0;         coreutilization[2] = 0;         coreutilization[3] = 0;     }     void addcore(shared_ptr<process_entry> * process, int currenttime)     {         if((core1 != null && core2 != null && core3 != null && core4 != null))         {             string processtype = process->get()->datastart->get()->text;             device_item * newentry = new device_item();             newentry->process = process;             newentry->finishtime = currenttime + process->get()->datacurrent->get()->time;             newentry->starttime = currenttime;              if(core1->process->get()->datastart->get()->text == "interactive" && processtype == "real-time")             {                 core1->finishtime = core1->finishtime - currenttime;                 iq.push(core1);                 core1 = newentry;             }             else if(core2->process->get()->datastart->get()->text == "interactive" && processtype == "real-time")             {                 core2->finishtime = core2->finishtime - currenttime;                 iq.push(core2);                 core2 = newentry;             }             else if(core3->process->get()->datastart->get()->text == "interactive" && processtype == "real-time")             {                 core3->finishtime = core3->finishtime - currenttime;                 iq.push(core3);                 core3 = newentry;             }             else if(core4->process->get()->datastart->get()->text == "interactive" && processtype == "real-time")             {                 core4->finishtime = core4->finishtime - currenttime;                 iq.push(core4);                 core4 = newentry;             }             else             {                 newentry->finishtime = 0;                 newentry->starttime = 0;                  if(process->get()->datacurrent->get()->text == "interactive")                 {                     iq.push(newentry);                     process->get()->state = process_state::waiting;                 }                 else                 {                     newentry->finishtime = process->get()->datacurrent->get()->time;                     rq.push(newentry);                     process->get()->state = process_state::waiting;                 }             }         }         else         {             device_item * newentry = new device_item();             newentry->process = process;             newentry->starttime = currenttime;             newentry->finishtime = currenttime + process->get()->datacurrent->get()->time;             process->get()->state = process_state::running;              if(core1 == null)                 core1 = newentry;             else if(core2 == null)                 core2 = newentry;             else if(core3 == null)                 core3 = newentry;             else if(core4 == null)                 core4 = newentry;         }      }     void adddisk(shared_ptr<process_entry> * disk, int currenttime)     {         device_item * newdisk = new device_item();         newdisk->process = disk;         newdisk->finishtime = currenttime + disk->get()->datacurrent->get()->time;         newdisk->starttime = currenttime;          if(disk1 == null)             disk1 = newdisk;         else         {             newdisk->finishtime = 0;             newdisk->starttime = 0;             diskq.push(newdisk);             disk->get()->state = process_state::waiting;         }     }     void checkcoreanddisk(int currenttime)     {         // stick queue if becomes empty. subtract time.          if(disk1 != null)         {             if(disk1->finishtime <= currenttime) {                 diskutilization += disk1->finishtime - disk1->starttime;                 disk1->process->get()->state = process_state::ready;                 durationdisk += disk1->finishtime - disk1->starttime;                 disk1 = null;                 completeddisk += 1;                  if(diskq.size() > 0) {                     disk1 = diskq.front();                     disk1->starttime = currenttime;                     disk1->finishtime = currenttime + disk1->process->get()->datacurrent->get()->time;                     diskq.pop();                     disk1->process->get()->state = process_state::running;                 }             }         }         if(core1 != null)         {             if(core1->finishtime <= currenttime) {                 coreutilization[0] += core1->finishtime - core1->starttime;                 core1->process->get()->state = process_state::ready;                 if(core1->process->get()->datastart->get()->text == "interactive") { completedinter += 1;  } else { completedreal += 1; };                  core1 = null;                  if(rq.size() > 0) {                     core1 = rq.front();                     core1->starttime = currenttime;                     core1->finishtime = currenttime + core1->finishtime;                     rq.pop();                     core1->process->get()->state = process_state::running;                 }                 else if(iq.size() > 0) {                     core1 = iq.front();                     core1->starttime = currenttime;                     core1->finishtime = currenttime + core1->finishtime;                     iq.pop();                     core1->process->get()->state = process_state::running;                 }             }         }         if(core2 != null)         {             if(core2->finishtime <= currenttime) {                 coreutilization[1] += core2->finishtime - core2->starttime;                 core2->process->get()->state = process_state::ready;                 if(core2->process->get()->datastart->get()->text == "interactive") { completedinter += 1; } else { completedreal += 1; };                 core2 = null;                  if(rq.size() > 0) {                     core2 = rq.front();                     core2->starttime = currenttime;                     core2->finishtime = currenttime + core2->finishtime;                     rq.pop();                     core2->process->get()->state = process_state::running;                 }                 else if(iq.size() > 0) {                     core2 = iq.front();                     core2->starttime = currenttime;                     core2->finishtime = currenttime + core2->finishtime;                     iq.pop();                     core2->process->get()->state = process_state::running;                 }             }         }         if(core3 != null)         {             if(core3->finishtime <= currenttime) {                 coreutilization[2] += core3->finishtime - core3->starttime;                 core3->process->get()->state = process_state::ready;                 if(core3->process->get()->datastart->get()->text == "interactive") { completedinter += 1; } else { completedreal += 1; };                 core3 = null;                  if(rq.size() > 0) {                     core3 = rq.front();                     core3->starttime = currenttime;                     core3->finishtime = currenttime + core3->finishtime;                     rq.pop();                     core3->process->get()->state = process_state::running;                 }                 else if(iq.size() > 0) {                     core3 = iq.front();                     core3->starttime = currenttime;                     core3->finishtime = currenttime + core3->finishtime;                     iq.pop();                     core3->process->get()->state = process_state::running;                 }             }         }         if(core4 != null)         {             if(core4->finishtime <= currenttime) {                 coreutilization[3] += core4->finishtime - core4->starttime;                 core4->process->get()->state = process_state::ready;                 if(core4->process->get()->datastart->get()->text == "interactive") { completedinter += 1; } else { completedreal += 1; };                 core4 = null;                  if(rq.size() > 0) {                     core4 = rq.front();                     core4->starttime = currenttime;                     core4->finishtime = currenttime + core4->finishtime;                     rq.pop();                     core4->process->get()->state = process_state::running;                 }                 else if(iq.size() > 0) {                     core4 = iq.front();                     core4->starttime = currenttime;                     core4->finishtime = currenttime + core4->finishtime;                     iq.pop();                     core4->process->get()->state = process_state::running;                 }             }         }     }      bool checkdeadlines()     {      }      bool checkcorefull()     {         return (core1 != null && core2 != null && core3 != null && core4 != null);     }      int printcompletedint()     {         return completedinter;     }      int printcompletedreal()     {         return completedreal;     }      int printcompleteddisk()     {         return completeddisk;     }      double printavgdiskduration()     {         return (durationdisk / completeddisk);     }      int printcoreutilization(int core)     {         return coreutilization[core - 1];     }      int printdiskutilization()     {         return diskutilization;     } };  void createdatatable(string file, vector<shared_ptr<data_entry>>  &datatable) {     string line;     ifstream myfile (file);     if (myfile.is_open())     {         int processamount = 0;          while ( getline (myfile,line) )         {             if(line.find("interactive") != string::npos)             {                 shared_ptr<data_entry> newentry = make_shared<data_entry>();                 newentry->text = "interactive";                 newentry->time = atoi(line.substr(12, 12).c_str());                  datatable.push_back(newentry);                  //shared_ptr<process_entry> newprocessentry = shared_ptr<process_entry>(new process_entry);                 //newprocessentry->datastart = &datatable.at(datatable.size() - 1);                 //newprocessentry->datacurrent = &datatable.at(datatable.size() - 1);                 //newprocessentry->process = processamount;                  //processtable.push_back(newprocessentry);                  processamount += 1;             }             else if (line.find("real-time") != string::npos)             {                 shared_ptr<data_entry> newentry = make_shared<data_entry>();                 newentry->text = "real-time";                 newentry->time = atoi(line.substr(10, 10).c_str());                 datatable.push_back(newentry);                 processamount += 1;             }             else if(line.find("end") != string::npos)             {                 shared_ptr<data_entry> newentry = make_shared<data_entry>();                 newentry->text = "end";                 newentry->time = -1;                 datatable.push_back(newentry);                  //processtable.at(processtable.size())->dataend = &datatable.at(datatable.size());             }             else if(line.find("run") != string::npos)             {                 shared_ptr<data_entry> newentry = make_shared<data_entry>();                 newentry->text = "run";                 newentry->time = atoi(line.substr(4, 4).c_str());                 datatable.push_back(newentry);             }             else if(line.find("tty") != string::npos)             {                 shared_ptr<data_entry> newentry = make_shared<data_entry>();                 newentry->text = "tty";                 newentry->time = atoi(line.substr(4, 4).c_str());                 datatable.push_back(newentry);             }             else if(line.find("disk") != string::npos)             {                 shared_ptr<data_entry> newentry = make_shared<data_entry>();                 newentry->text = "disk";                 newentry->time = atoi(line.substr(5, 5).c_str());                 datatable.push_back(newentry);             }             else if(line.find("deadline") != string::npos)             {                 shared_ptr<data_entry> newentry = make_shared<data_entry>();                 newentry->text = "deadline";                 newentry->time = atoi(line.substr(9, 9).c_str());                 datatable.push_back(newentry);             }         }     }      myfile.close(); }  void createprocesstable(vector<shared_ptr<data_entry>> &datatable, vector<shared_ptr<process_entry>> &processtable) {     int processamount = 0;      for(size_t = 0; < datatable.size(); i++)     {         if(datatable.at(i)->text == "interactive" || datatable.at(i)->text == "real-time")         {             shared_ptr<process_entry> newprocessentry = make_shared<process_entry>();             newprocessentry->datastart = &datatable.at(i);             newprocessentry->datacurrent = &datatable.at(i);             newprocessentry->process = processamount;             newprocessentry->state = process_state::p_none;             newprocessentry->totaltime = 0;              if(datatable.at(i + 1)->text == "deadline")                 newprocessentry->deadline = datatable.at(i + 1)->time;             else                 newprocessentry->deadline = -1;              processtable.push_back(newprocessentry);              processamount += 1;         }         else if(datatable.at(i)->text == "end")         {             processtable.back()->dataend = &datatable.at(i);         }          if(processtable.size() > 0 && datatable.at(i)->text != "deadline" && datatable.at(i)->time != -1)         {             processtable.back()->totaltime += datatable.at(i)->time;         }     } }  void createeventtable(vector<shared_ptr<process_entry>> &processtable, vector<shared_ptr<event_entry>> &eventtable) {     for(size_t = 0; < processtable.size(); i++)     {         shared_ptr<event_entry> newevententry = make_shared<event_entry>();         newevententry->process = &processtable.at(i);         newevententry->time = newevententry->process->get()->datastart->get()->time;         newevententry->component = event_component::e_none;         eventtable.push_back(newevententry);     } }  bool sorteventtable(shared_ptr<event_entry> i, shared_ptr<event_entry> j) {     return (i->time < j->time); }  int main(int argc, const char *argv[]) {     int currenttime = 0;     int deadlineamount = 0;      vector<shared_ptr<data_entry>>  datatable;     vector<shared_ptr<process_entry>> processtable;     vector<shared_ptr<event_entry>> eventtable;     device_table newdevice;      createdatatable(argv[1], datatable);     createprocesstable(datatable, processtable);     createeventtable(processtable, eventtable);     std::sort (eventtable.begin(), eventtable.end(), sorteventtable);      while(eventtable.size() > 0)     {         std::sort (eventtable.begin(), eventtable.end(), sorteventtable);          newdevice.checkcoreanddisk(currenttime);         //newdevice.printall();         string currenttext = eventtable.at(0).get()->process->get()->datacurrent->get()->text;         if(currenttext == "run")         {             eventtable.at(0).get()->component = event_component::core;             newdevice.addcore(eventtable.at(0).get()->process, currenttime);         }         else if(currenttext == "real-time" || currenttext == "interactive")         {              eventtable.at(0).get()->component = event_component::start;         }         else if(currenttext == "disk")         {             eventtable.at(0).get()->component = event_component::disk;             newdevice.adddisk(eventtable.at(0).get()->process, currenttime);         }         else if(currenttext == "tty")         {             eventtable.at(0).get()->component = event_component::tty;         }          if(eventtable.at(0).get()->process->get()->datacurrent->get()->text == "end")         {             //cout << eventtable.at(0).get()->time << "\n";             if(eventtable.at(0).get()->process->get()->deadline == 1)             {              }             eventtable.erase(eventtable.begin());         }         else         {             //cout << eventtable.at(0).get()->time << "\n";             eventtable.at(0).get()->process->get()->datacurrent += 1;              if(currenttext != "deadline")                 currenttime = eventtable.at(0).get()->time;              if(eventtable.at(0).get()->process->get()->datacurrent->get()->time != -1 && currenttext != "deadline")                 eventtable.at(0).get()->time = currenttime + eventtable.at(0).get()->process->get()->datacurrent->get()->time;         }          //cout << newdevice.checkcorefull() << "\n";     }      for(size_t = 0; < processtable.size(); i++)     {         if(processtable.at(i)->deadline != -1)         {             if (processtable.at(i)->totaltime > processtable.at(i)->deadline)                 deadlineamount += 1;         }     }      cout << "completed interactive : " << newdevice.printcompletedint() << "\n";     cout << "completed real-time   : " << newdevice.printcompletedreal() << "\n";     cout << "completed disk        : " << newdevice.printcompleteddisk() << "\n";     cout << "core1 utilization     : " << newdevice.printcoreutilization(1) << "\n";     cout << "core2 utilization     : " << newdevice.printcoreutilization(2) << "\n";     cout << "core3 utilization     : " << newdevice.printcoreutilization(3) << "\n";     cout << "core4 utilization     : " << newdevice.printcoreutilization(4) << "\n";     cout << "disk utilization      : " << newdevice.printdiskutilization() << "\n";     cout << "average disk duration : " << newdevice.printavgdiskduration() << "\n";     cout << "% missed deadline     : " << ((float)deadlineamount / processtable.size()) * 100 << "%\n";     cout << "total elapsed time    : " << currenttime << "\n";      int input;     cin >> input;     return 0;  } 

you may want compile code c++11 support:

g++ -std=c++11 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -