Member inaccessibility error

I need some help with accessing a member from a protected class.
The error is on line 17 of my .cpp file and its saying its inaccessible. But if it's inaccessible then why did an error message not generate for lines 11 and 12? The members are length and width in my rectangleType.h file


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
31
32
33
34
35
36
37
  #ifndef rectangleType_h
#define rectangleType_h
#include <iostream>
using namespace std;

class rectangleType
{
	friend ostream& operator<<(ostream&, const rectangleType&);//overloads stream insertion operator
	friend istream& operator>>(istream&, rectangleType&);//overloads extraction operators
	friend rectangleType operator++(rectangleType&);//pre-increment
	friend rectangleType operator--(rectangleType&);//pre-decrement
	friend rectangleType operator++(rectangleType&, int);//post - increment
	friend rectangleType operator--(rectangleType&, int);//post-decrement
	friend rectangleType operator+(const rectangleType&, const rectangleType&);//overload + operator
	friend rectangleType operator-(const rectangleType&, const rectangleType&);//overload - operator
	friend rectangleType operator*(const rectangleType&, const rectangleType&);//overload * operator
	friend bool operator==(const rectangleType&, const rectangleType&);//overload == operator, relational
	friend bool operator!=(const rectangleType&, const rectangleType&);//overload != operator
	friend bool operator<=(const rectangleType&, const rectangleType&);//overload <= operator
	friend bool operator<(const rectangleType&, const rectangleType&);//overload < operator
	friend bool operator>=(const rectangleType&, const rectangleType&);//overload >= operator
	friend bool operator>(const rectangleType&, const rectangleType&);//overload>+ operator
public:
    void setDimension(double l, double w);
    double getLength() const;
    double getWidth() const;
    double area() const;
    double perimeter() const;
    rectangleType();//class constructor
    rectangleType(double l, double w);//class constructor with parameters
protected:
	double length;
	double width;
    

};
#endif 

The beginning portion of the .cpp file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <iomanip>
#include <cstring>
#include<cassert>
using namespace std;
#include "rectangleType.h"


ostream& operator<<(ostream& osObject, const rectangleType& rec)
{//member functions of rectangleType overload the stream insertion << operator
	osObject << "Length = " << rec.length //There is NO error here.
		<< ", Width = " << rec.width;//No error
	return osObject;
}
istream& operator>>(istream& isObject, rectangleType rec)
{//stream extraction operator overloaded
	isObject >> rec.length >> rec.width; //ERROR!??? Why?
	return isObject;
}
Last edited on
Your class seems to be quite popular. Also, a lot of those operator look abused.

About your error, compare
1
2
friend istream& operator>>(istream&, rectangleType&); //declaration
istream& operator>>(istream& isObject, rectangleType rec) //definition 
Thanks for your eyes! I stared and stared but somehow how didn't see it.
Topic archived. No new replies allowed.