So, I'm working with inheritance for the first time. The concept and implementation seemed pretty straight forward after reviewing the tutorial on this site. However, my derived class seems to be unable to see the protected members of the parent class. It's probably some syntactical nuance I don't see. The offending classes and, in the event its relevant, the function calls from main() are below
class SteamTable
{
public:
SteamTable();
virtual ~SteamTable();
staticconst size_t minCols = 3; // Minimum number of columns in the table
virtualvoid generateTable(helmholtz::num_t low, helmholtz::num_t high, helmholtz::num_t pInterval);
virtualvoid printTable(std::ostream& os);
virtualvoid precision(int p);
virtualint precision();
protected:
virtualvoid verifyRange();
State* state; // Pointer to a State object to be used for calculations
std::ostream os; // Ostream object to which the table will be output.
std::vector<std::string> outStrings; // Container of the strings to be output
std::vector<size_t> colWidth; // Width of each column
size_t numCols; // Number of columns in the Table
unsignedint nTable; // Table type: 1 == Tsat, 2 == Psat, 3 == Superheated steam, 4 == Subcooled & superheated simple grid
int prec; // Precision of the output
helmholtz::num_t low, high, pInterval; // Lowest & highest limits and interval of independent property
private:
};
class STable1 : public SteamTable
{
public:
STable1();
virtual ~STable1();
virtualvoid generateTable(helmholtz::num_t low, helmholtz::num_t high, helmholtz::num_t pInterval);
virtualvoid printTable(std::ostream& os);
staticconstunsignedint nTable = 1;
protected:
private:
};
To reduce size of the initial post, I didn't include the functions generating the result, as I believed it was likely some problem with the declaration. As I went to copy the function, I discovered the problem: I didn't have the Class identifier (STable1::) on my function names in my implementation. I've cleaned that up and corrected the error, but now I've got a completely (I think) unrelated error that I have no idea how to approach. Using the class declarations above:
1 2 3 4 5
SteamTable::SteamTable()
{
//ctor
state = new State;
}
error:[1] ‘std::basic_ostream<_CharT, _Traits>::basic_ostream() [with _CharT = char; _Traits = std::char_traits<char>]’ is protected within this context
You are posting bits and pieces that aren't actually causing problems. You use an ostream& in printTable(). Why not post that code?
Does the error point to this constructor? You suggest that it does, but you don't really give us much context. I suspect that printTable() tries to create a SteamTable object of some sort and the constructor of the base class happens to be the last thing processed before the error is encountered.
By the way, line 16 in the first post won't work. std::ostream cannot be created without a streambuf* argument.
Edit: wait, I don't know what your constructor does, so it might be OK. However, I doubt you need this member because you pass a std::ostream& in printTable().
Yeah, I realized after doug4's original post that I wouldn't need that member anyway because I'm passing it in by reference. I'm encountering other issues now, but it's completely unrelated to the original problem or the second one.