my class function says that I have an undeclared variable

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
#include "stdafx.h"
#include "amfluid.h"



amfluid::amfluid(int gall, int quar, int pin)
{
	gallon = gall;
	quart = quar;
	pint = pin;
	reduce();
}

void reduce()
{
	int temp;
	while (pint >= 2)
	{
		temp = pint/ 2;
		quart += temp;
		pint = pint-(2*temp);
	}
	while (quart >= 4)
	{
		temp = quart/ 4;
		gallon += temp;
		quart = quart-(4*temp);
	}


}

int amfluid::getgallon()
{	 return gallon;
}

int amfluid::getquart()
{
	return quart;
}
	


int amfluid::getpint()
{return pint;
}


	
void addpint(void)
{
	pint += 1;
	reduce();
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "stdafx.h"

class amfluid
{
	int gallon;
	int quart;
	int pint;

	void reduce(void);

public:
	amfluid(int gall, int quar, int pin);
	int getgallon(void);
	int getquart(void);
	int getpint(void);
	void addpint(void);

};



I get an error that says that pint is an undeclared identifier inside of the reduce function that starts on line 14. It also doesn't compile beyond that for that very reason. obviously I have no idea why this is, can anyone help me?
'reduce' isn't a member of 'amfluid' so it can't know which other members are in there
Not sure, but it seems you make have declared pint inside the context of the amfluid class. But reduce() does not include amfluid in the header of the definition.
eg

1
2
3
void amfluid::reduce()
{ //your code
}


At least that is a possibility.
Wow, now I feel like an idiot. How did I not see that? thanks guys
Topic archived. No new replies allowed.