Template with Inheritance C++ -


using inheritance , templates, ive sort name array of employee information. got 3 classes, payroll, simplevector , sortingvector. payroll contains user info attributes, simplevector creates dynamic array of type payroll store user info. sortingvector class in charge of sorting array names. keep getting many different errors whenever tried fix previous error.

posting each class:

payroll class

    #pragma once #include<iostream> #include<string> #include<vector> using namespace std;  class payroll { private:       int empnumber;     string name;     double  hours;     double payrate;     double grosspay;      int *aptr;     int arraysize;  public:        payroll(int size);     payroll();     payroll(const payroll & apayroll);     ~payroll();      //mutators      void setvector(payroll &apayroll);      void setempnumber(int empnumber);      void setname(string name);      void sethours(double hours);      void setpayrate(double payrate);      void setgrosspay(double grosspay);     //accessors      int getempnumber()const;      string getname()const;      double gethours()const;      double getpayrate()const;      double getgrosspay()const;      payroll &operator =(const payroll &apayroll);      bool operator ==(const payroll &apayroll) const;       friend ostream & operator << (ostream & output, const payroll & apayroll);      friend istream & operator >> (istream & input, payroll & apayroll);   };  //cpp  payroll::payroll() : empnumber(0), name(""), hours(0.00), payrate(0.00), grosspay(0.00) {}   payroll::payroll(const payroll & apayroll) : empnumber(apayroll.empnumber), name(apayroll.name), hours(apayroll.hours), payrate(apayroll.payrate), grosspay(apayroll.grosspay) {}    payroll::~payroll() {  }  //mutators  void payroll::setempnumber(int empnumber) {     this->empnumber = empnumber; }  void payroll::setname(string name) {     this->name = name; }   void payroll::sethours(double hours) {     this->hours = hours; }  void payroll::setpayrate(double payrate) {     this->payrate = payrate; }  void payroll::setgrosspay(double  grosspay) {     this->grosspay = grosspay; }  //accessors  int payroll::getempnumber()const {     return(this->empnumber); }   string payroll::getname()const {     return(this->name); }   double payroll::gethours()const {     return(this->hours); }   double payroll::getpayrate()const {     return(this->payrate); }  double payroll::getgrosspay()const {      return(this-> hours * payrate); }  payroll &payroll::operator = (const payroll &apayroll) {      this->name = apayroll.name;     this->empnumber = apayroll.empnumber;     this->hours = apayroll.hours;     this->payrate = apayroll.payrate;     this->grosspay = apayroll.grosspay;      return(*this);   }  bool payroll::operator ==(const payroll &apayroll) const {      bool equal = this->name == apayroll.name;      return(equal);   } 

simplevector class

#ifndef simplevector_h #define simplevector_h  #include <iostream> #include <cstdlib> #include "c:\users\jorge\dropbox\payroll class\payroll.h" using namespace std;   template <class type> class simplevector {  private:     type *aptr;     int arraysize;     void suberror();  public:     simplevector(int);     simplevector(const simplevector &avector);     ~simplevector();     int size() {         return arraysize;     }      type &operator [](int);     void print();  };  template <class type> simplevector<type>::simplevector(int s) {      arraysize = s;     aptr = new type[s];     (int count = 0; count < arraysize; count++)         aptr[count] = type(); }  template <class type> simplevector<type>::simplevector(const simplevector &avector) {      arraysize = avector.arraysize;     aptr = new type[arraysize];     (int count = 0; count < arraysize; count++)         aptr[count] = avector[count]; }  template <class type> simplevector<type>::~simplevector(){      if (arraysize > 0)         delete[] aptr; }  template <class type> void simplevector<type>::suberror() {     cout << "error: subscript out of range.\n";     exit(0); }  template <class type> type &simplevector<type>::operator[](int sub) {      if (sub < 0 || sub >= arraysize)         suberror();      return aptr[sub]; }  template <class type> void simplevector<type>::print() {      (int k = 0; k < arraysize; k++)         cout << aptr[k] << " ";     cout << endl; }   #endif 

sortingarray class

#ifndef sortingvector_h #define sortingvector_h  #include "simplevector.h" #include <iostream> #include <string>  template <class t> class sortingvector : public simplevector<t> {  public:     sortingvector(int s) : simplevector<t>(s) {}     sortingvector(sortingvector &asort);     sortingvector(simplevector<t> &avector) : simplevector<t>(avector) {}      void sortingbyname(simplevector<payroll> &avector);     }; #endif   template <class t> sortingvector<t>::sortingvector(sortingvector &avector) : simplevector<t>(avector) {}  template <class t> void sortingvector<t>::sortingbyname(simplevector<payroll> &avector) {      bool swap;     sortingvector<payroll> temp;      int x;      {          swap = false;         (int = 0; < avector.arraysize; i++) {               x = strcmp(avector[i], avector[i + 1]);             if (x > 0) {                  temp = avector[i];                 avector[i] = avector[i + 1];                 avector[i + 1] = temp;                 swap = true;              }         }     } while (swap);  } 

the errors right are:

error   2   error c2248: 'simplevector<payroll>::arraysize' : cannot access private member declared in class 'simplevector<payroll>'    c:\users\jorge\dropbox\simplevector\simplevector\sortingvector.h    39  1   simplevector error   1   error c2512: 'sortingvector<payroll>' : no appropriate default constructor available    c:\users\jorge\dropbox\simplevector\simplevector\sortingvector.h    32  1   simplevector error   3   error c2664: 'int strcmp(const char *,const char *)' : cannot convert argument 1 'payroll' 'const char *'   c:\users\jorge\dropbox\simplevector\simplevector\sortingvector.h    42  1   simplevector error   4   error c2679: binary '=' : no operator found takes right-hand operand of type 'payroll' (or there no acceptable conversion)   c:\users\jorge\dropbox\simplevector\simplevector\sortingvector.h    45  1   simplevector error   5   error c2679: binary '=' : no operator found takes right-hand operand of type 'sortingvector<payroll>' (or there no acceptable conversion)    c:\users\jorge\dropbox\simplevector\simplevector\sortingvector.h    47  1   simplevector 

sortingvector<payroll> temp(); not parsed expected (vexing parse), want:

sortingvector<payroll> temp; 

or

sortingvector<payroll> temp{}; /* since c++11 */ 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -