Trouble with Private int

I know I can't access a private member of a class but I don't know what I should be using instead. Here's some of the code. (I can't make it public becauce our instruction said we weren't supposed to.)

ShapeDrawer.h
1
2
3
...
private:
int pixeldata[3 * N_ROWS * N_COLS];


ShapeDrawer.cpp
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
void ShapeDrawer::writeFile(string fileName)
{
	ofstream outFile;
	outFile.open(fileName.c_str());
	outFile << "P3" << endl << "100\n100\n255\n" << endl;
	for (int j = 0; j < N_ROWS; j++)
		for (int i = 0; i < N_COLS; i++)
			outFile << pixeldata[3*(j*N_COLS+i)] << " " << pixeldata[3*(j*N_COLS+i)+1] << " " << pixeldata[3*(j*N_COLS+i)+2] << endl;
	outFile.close();
}

void ShapeDrawer::initArray()
{
	for (int i = 0; i < (3*N_ROWS*N_COLS); i++) {
		pixeldata[i] = 0;
	}
}
void ShapeDrawer::setPixel(int X, int Y, char color, int data) {
	int outtieX;
	int outtieY;

	Y = (N_ROWS-1) - Y;

	outtieX = X;
	outtieY = Y;
	if ((X < 0)||(X > N_COLS)||(Y < 0)||(Y > N_ROWS)) {
		return;
	}

	switch (color) {
		case 'R': pixeldata[(3*((outtieY * (N_COLS)) + outtieX))] = data;
			break;
		case 'G': pixeldata[(3*((outtieY * (N_COLS)) + outtieX))+1] = data;
			break;
		case 'B': pixeldata[(3*((outtieY * (N_COLS)) + outtieX))+2] = data;
			break;
	}
}
void ShapeDrawer::setOnePixel(int X, int Y, int data) {
	setPixel(X, Y, 'R', data);
	setPixel(X, Y, 'G', data);
	setPixel(X, Y, 'B', data);
}
void ShapeDrawer::drawLine(Line l) {
	int xa = l.getStart().getX();
	int ya = l.getStart().getY();
	int xb = l.getEnd().getX();
	int yb = l.getEnd().getY();
	int red = l.getColor().getRed();
	int blue = l.getColor().getBlue();
	int green = l.getColor().getGreen();
	int negSlope = 0;
	int bigSlope = 0;
	int dx = abs(xb-xa), dy = abs(yb-ya);
	int p, twoDx, twoDy, twoDyDx;
	int x, y, xEnd, yEnd;

	if ((((float) dy / (float) dx)) > 1) {
		bigSlope = 1;
	}

	// -1 > Slope > 1
	if (bigSlope == 0) {
		twoDy = 2 * dy;
		twoDyDx = 2 * (dy - dx);
		p = 2 * dy - dx;

		if (xa > xb) {
			x = xb;
			y = yb;
			xEnd = xa;
			if ((ya-yb) < 0) {
				negSlope = 1;
			}
		}
		else {
			x = xa;
			y = ya;
			xEnd = xb;
			if ((yb-ya) < 0) {
				negSlope = 1;
			}
		}
		setPixel(x, y, 'R', red);
		setPixel(x, y, 'G', green);
		setPixel(x, y, 'B', blue);
		
		// Slope > 0
		if (negSlope == 0) {
		    while (x < xEnd) {
				x++;
				if (p < 0)
					p += twoDy;
				else {
					y++;
					p += twoDyDx;
				}
				setPixel(x, y, 'R', red);
				setPixel(x, y, 'G', green);
				setPixel(x, y, 'B', blue);
			}
		}
		// Slope < 0
		else {
			while (x < xEnd) {
				x++;
				if (p < 0)
					p += twoDy;
				else {
					y--;
					p += twoDyDx;
				}
				setPixel(x, y, 'R', red);
				setPixel(x, y, 'G', green);
				setPixel(x, y, 'B', blue);
			}
		}
	}
	// -1 > Slope > 1
	else {	
		twoDx = 2 * dx;
		twoDyDx = 2 * (dx - dy);
		p = 2 * dx - dy;

		if (xa > xb) {
			x = xb;
			y = yb;
			yEnd = ya;
			if ((ya-yb) < 0) {
				negSlope = 1;
			}
		}
		else {
			x = xa;
			y = ya;
			yEnd = yb;
			if ((yb-ya) < 0) {
				negSlope = 1;
			}
		}
		setPixel(x, y, 'R', red);
		setPixel(x, y, 'G', green);
		setPixel(x, y, 'B', blue);
		// Slope > 1
		if (negSlope == 0) {
			while (y < yEnd) {
				y++;
				if (p < 0)
					p += twoDx;
				else {
					x++;
					p += twoDyDx;
				}
				setPixel(x, y, 'R', red);
				setPixel(x, y, 'G', green);
				setPixel(x, y, 'B', blue);
			}	
		}
		// Slope < -1
		else {
			while (y > yEnd) {
				y--;
				if (p <= 0)
					p += twoDx;
				else {
					x++;
					p += twoDyDx;
				}
				setPixel(x, y, 'R', red);
				setPixel(x, y, 'G', green);
				setPixel(x, y, 'B', blue);
			}
		}	
	}
}


And this is where I'm trying to put it.
1
2
3
ShapeDrawer.writeFile(file);
ShapeDrawer.drawLine(Line);
ShapeDrawer.setOnePixel(ShapeDrawer::N_COLS, ShapeDrawer::N_ROWS, pixeldata);


Error is 'pixeldata'undeclared (first use of this function)
You are passing pixeldata, which is an int array to a method expecting an int.
So what should I be passing?
If pixeldata is a data member of ShapeDrawer, then you don't need to pass it at all.
Topic archived. No new replies allowed.