istream& Student_info::read(istream& is)
{
delete cp;
char ch;
cout << "Type U for undergraduate, or G for graduate" << endl;
is >> ch; // get record type
if (ch == 'U')
cp = new Core(is); // When I pass is, I get the error.
elseif (ch == 'G')
cp = new Grad(is); // When I pass is, I get the error.
else
{
cp = 0;
cout << "You didn't pick G or U" << endl;
}
return is;
}
Here's the error
Error 1 error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>' c:\program files (x86)\microsoft visual studio 10.0\vc\include\istream 860
Probably, the constructors for Core and Grad take an ifstream as an argument, not an ifstream&. The common ways of copying a stream object (=, copy constructors, etc) are protected, meaning you can't (easily) copy a stream object, and I don't think they were meant to be copied.
#ifndef GUARD_Core_h
#define GUARD_Core_h
#include <iostream>
#include <string>
#include <vector>
class Core
{
// Friends
frienddouble grade(const Core&);
friendclass Student_info;
public:
// Constructors
Core(): midterm(0), final(0) { }
Core(std::istream is) { read(is); }
// Virtual destructor
virtual ~Core() {}
// Virtual functions
virtual std::istream& read(std::istream&);
virtualdouble grade() const;
/*Virtual function: If the argument is a Grad object,
it will run the Grad::grade function; if the argument is a Core object, it will run the Core::grade
function.*/
/*This run-time selection of the virtual function to execute is relevant only when the function is called
through a reference or a pointer.*/
/*In contrast, a reference or pointer
to a base-class object may refer or point to a base-class object, or to an object of a type derived
from the base class, meaning that the type of the reference or pointer and the type of the object to
which a reference or pointer is bound may differ at run time. It is in this case that the virtual
mechanism makes a difference.*/
std::string name() const;
bool valid() const { return homework.empty(); }
protected:
virtual Core* clone() const { returnnew Core(*this); }
// Accessible to derived classes
std::istream& read_common(std::istream&);
double midterm, final;
std::vector<double> homework;
private:
// Accessible only to Core or friends
std::string n;
};
bool compare(const Core&, const Core&);
bool compare_Core_ptrs(const Core*, const Core*);
std::istream& read_hw(std::istream&, std::vector<double>&);
#endif