Feb 18, 2016 at 10:34pm UTC
I am trying to print out a list, compiler is giving me the error mentioned in the title. I've marked below where I am getting my error at: (***)
Thank you to anyone who takes time to look over this
main:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "UListType.h"
#include "UListType.h"
#include "OListType.h"
#include <iostream>
using namespace std;
int main() {
//UListType <int>ulist;
OListType <int >olist(10);
for (int i = 11; i > 0; --i) {
olist.insert(i);
}
cout << olist << endl; // **************error here******************
cout << "Ordered list capacity: " << olist.cap() << endl; //**********Error here stating olist.cap() is inacessible*******************
system("pause" );
return 0;
}
header file 1:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#ifndef OLISTTYPE__H
#define OLISTTYPE__H
#include "ListType.h"
template <typename T>
class OListType:ListType<T>{
public :
OListType(size_t = 10);
bool insert(const &T);
private :
void insert_item(const int );
};
#endif
header file 2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
#ifndef LISTTYPE__H
#define LISTTYPE__H
#include <iostream>
template <typename T>
class ListType {
public :
ListType(size_t = 10);
ListType(const ListType<T>&);
~ListType() : virtual ;
operator =(const ListType<T>&) : const ListType<T>&;
virtual bool insert(const T&) = 0;
virtual bool eraseAll();
virtual bool : erase(const T&) = 0;
size_t size() const ;
bool empty() const ;
bool full() const ;
void print() const ;
size_t cap() const ;
friend std::ostream& operator << (std::ostream&, const ListType&);
protected :
int * list;
size_t capacity;
size_t count;
};
Last edited on Feb 18, 2016 at 10:35pm UTC
Feb 19, 2016 at 1:10am UTC
Hi,
My thought was that, In class ListType:
friend std::ostream& operator << (std::ostream&, const ListType&);
The friend privilege isn't inherited.
Did you have a definition for the operator <<
? Normally one has to tell the compiler how to print the object. So you might need to overload operator <<
for the derived class as well.
I am not completely sure of the details of all this, someone else might have a better idea :+)
Feb 19, 2016 at 5:49am UTC
class OListType:ListType<T>
is equivalent to class OListType: private ListType<T>