Need direction with my Class declaration, and probably a few other things...

I am having some trouble with my Class declaration and definitions. Specifically defining the class with specific declarations and variables, and then using them later in the main file but getting errors. I am sure there are numerous errors that others can see, such as variables being defined and not used. At this point I have been staring at the screen for several days and haven't gotten any further in the code. If anyone can help I would appreciate it. Also, I do know that the code isn't entirely complete since I will be sending the info to Standard Out and haven't typed that bit just yet. Anyway, I would like to fix these errors first. Thanks in advance for the help.

Class 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
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
#include <iostream>
#include <string>

using namespace std;

class Color
{
	private:
		int red;
		int green;
		int blue;

	public:
		Color();
		Color(int, int, int);
		char add(char);
		char mix(char);
		int set(int, int, int);
		int r;
		int g;
		int b;
		int R();
		int G();
		int B();

		int GetR();
		int GetG();
		int GetB();
		int Getset();
		char Getmix();
		char Getadd();

		void Setcolor(int, int, int);
		void Setset(char, char, char);
		void Setmix(char);
		void Setadd(char);
		void SetR(int);
		void SetG(int);
		void SetB(int);

};
Color::Color()
{
	red = green = blue = 0;
}

Color::Color(int, int, int)
{
	int r = red;
	int g = green;
	int b = blue;
}

int Color::GetR()
{
	return red;
}

int Color::GetG()
{
	return green;
}

int Color::GetB()
{
	return blue;
}

int Color::set(int, int, int)
{
	int set_r = r;
	int set_g = g;
	int set_b = b;
}

char Color::mix(char)
{
	char mix();
}

char Color::add(char)
{
	char add();
}


Main 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
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <cstring>
#include <cmath>
#include "color.h"

using namespace std;

int main()
{
	
	const Color Black;
	const Color White(255, 255, 255);
	const Color SkyBlue(135, 206, 235);
	const Color SeaGreen(46, 139, 87);
	const Color Gold(255, 215, 0);
	const Color Chocolate(210, 105, 30);
	const Color DarkGrey(75, 75, 75);

	Color Custom(White);
	Custom.mix(DarkGrey);
	Custom.mix(SkyBlue);

	Color CreamyMix(White);
	CreamyMix.mix(SkyBlue);
	CreamyMix.mix(SeaGreen);
	CreamyMix.mix(White);
	CreamyMix.mix(White);

	Color mixes[5];
	mixes[0] = SkyBlue;
	mixes[0].add(SeaGreen);
	mixes[0].mix(Black);

	mixes[1].set(SeaGreen.R(), DarkGrey.G(),Chocolate.B());
	mixes[1].mix(Gold);

	mixes[2] = White;
	mixes[2].add(Black);
	mixes[2].add(Gold);

	mixes[3].set(Chocolate.R(), Gold.G(), SeaGreen.B());
	mixes[3].add(SkyBlue);

	mixes[4] = mixes[3];
	mixes[4].mix(Black);
	mixes[4].mix(Black);
}
1
2
3
4
5
6
Color::Color(int, int, int) //anonimous parameters
{
	int r = red; //local variables, assigned with garbage
	int g = green;
	int b = blue;
}//local variables die 
Same for set.

1
2
3
4
char Color::mix(char)
{
	char mix();
}
Does this ever compile?
No it doesn't, which is why I was turning to here for help since I couldn't figure out what the heck I was doing wrong. I may have a bit more of it figured out at this point, but am still running into errors. Things are going crazy today with food and such so I may have to work on it later. I will post the latest results most likely this evening.
Okay, I have changed around a bunch of the code and only have a few errors that are showing now. Realistically there are only two errors, but they show up multiple times. The code still won't compile. Those three errors are:

"Cannot convert from 'this' pointer from 'const Color' to 'Color&'" (this repeats for each of the instances where I call on them from the main file.)

"redefinition of formal parameter init_r" (this repeats for each of the init parts in the implementation file.)

and finally,

"'Color::operator=' : cannot define a compiler-generated special member function (must be declared in the class first)

If anyone can help me with this I would appreciate it. Thanks in advance.

Code as I have it written currently:

Header 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
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#ifndef __COLOR_H_INCLUDED__
#define __COLOR_H_INCLUDED__

using namespace std;

class Color
{
	private:
		int red;
		int green;
		int blue;

	public:
		Color();
		Color(int, int, int);
		void set(int, int, int);
		int r;
		int g;
		int b;
		int init_r;
		int init_g;
		int init_b;
		void R();
		void G();
		void B();
		int newR;
		int newG;
		int newB;

		int GetR();
		int GetG();
		int GetB();
		int set();
		char mix();
		char add();

		void color(int, int, int);
		void Setset(int, int, int);
		void mix(const Color& col);
		void add(const Color& col);
		void SetR(const Color& param);
		void SetG(const Color& param);
		void SetB(const Color& param);

};
#endif

Implementation 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

#include  "color.h"


Color::Color()
{
	red = green = blue = 0;
}

Color::Color(int init_r, int init_g, int init_b)
{
	int init_r = red;
	int init_g = green;
	int init_b = blue;
}

void Color::set(int newR, int newG, int newB)
{
	int n_r = newR;
	int n_g = newG;
	int n_b = newB;
}

Color& Color::operator= (const Color& param)
{
	return *this;
}

void Color::R()
{
	return r;
}

void Color::G()
{
	return g;
}

void Color::B()
{
	return b;
}

void Color::mix(const Color& col)
{
	void mix(const Color& col);
}

void Color::add(const Color& col)
{
	void add(const Color& col);
}


Main 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
38
39
40
41
42
43
44
45
#include <iostream>
#include "color.h"

using namespace std;

int main()
{
	
	const Color Black;
	const Color White(255, 255, 255);
	const Color SkyBlue(135, 206, 235);
	const Color SeaGreen(46, 139, 87);
	const Color Gold(255, 215, 0);
	const Color Chocolate(210, 105, 30);
	const Color DarkGrey(75, 75, 75);

	Color Custom(White);
	Custom.mix(DarkGrey);
	Custom.mix(SkyBlue);

	Color CreamyMix(White);
	CreamyMix.mix(SkyBlue);
	CreamyMix.mix(SeaGreen);
	CreamyMix.mix(White);
	CreamyMix.mix(White);

	Color mixes[5];
	mixes[0] = SkyBlue;
	mixes[0].add(SeaGreen);
	mixes[0].mix(Black);

	mixes[1].set(SeaGreen.R(), DarkGrey.G(),Chocolate.B());
	mixes[1].mix(Gold);

	mixes[2] = White;
	mixes[2].add(Black);
	mixes[2].add(Gold);

	mixes[3].set(Chocolate.R(), Gold.G(), SeaGreen.B());
	mixes[3].add(SkyBlue);

	mixes[4] = mixes[3];
	mixes[4].mix(Black);
	mixes[4].mix(Black);
}
mixes[1].set(SeaGreen.R(), DarkGrey.G(),Chocolate.B());

This is the line of code that is giving me the most trouble. I know how to instantiate the first part of the class with the set portion, it's the .R(), .G(), and .B() that I am not understanding how to implement.
Cannot convert from 'this' pointer from 'const Color' to 'Color&'
I suppose that is complaining about not having const methods. If your method doesn't modify the state of your object, declare it const void Color::R() const (this is the only way for using it with constants objects)

redefinition of formal parameter init_r
1
2
3
4
5
6
Color::Color(int init_r, int init_g, int init_b)
{
	int init_r = red; //you are creating new variables with the same name of your parameters
	int init_g = green;
	int init_b = blue;
}


'Color::operator=' : cannot define a compiler-generated special member function (must be declared in the class first)



1
2
3
4
void Color::add(const Color& col)
{
	void add(const Color& col); //why are you declaring a function here?
}
Topic archived. No new replies allowed.