Quick question about classes/pointers

Hey, I'm working on an assignment for a class of mine that requires coding the Burnt Pancake problem using pointers. I had a quick question about something that has been puzzling me. This directly below is a part of one of my functions in a class I made, and I am wondering how do I make stack from line 6 an undeclared identifier?

1
2
3
4
5
6
7
8
9
10
void DStack::Insert(ItemType)
{
	NodePtr currPtr;

	currPtr = new NodeType;
	currPtr ->cake = stack;	//stores pancake into node
	currPtr ->link = NULL;


}


Below is the whole BurntPancake Itemtype cake relationship that I have in a header file which I did #include into my class's cpp file.

1
2
3
4
5
6
7
8
typedef BurntPancake ItemType;

struct NodeType
{
	ItemType cake; // one pancake
	NodeType* link; //Link to next node in list

};


In my code with main and everything else, I declared "BurntPancake stack;" as one of the lines.
Last edited on
I think you are missing a name after ItemType in that function (maybe you meant to call it "stack")?
That's another thing that confuses me sometimes too. How do variables (in terms of classes) work when they first appear in the function argument? In the header you just say the function title and the types in it. Then in that class's cpp file you make a name for that argument in the function declaration line.
Its not initialized by normal means that I can find, so how does that work?
Hm? I'm not sure what you mean by "first appear in the function argument"?

Classes work exactly like normal variables:
1
2
3
4
int x;
double y;
MyClass z;
std::string str; //etc 
For example:

In the header file you have:
void SetSize(int);

In the cpp file you have:
1
2
3
4
5
void BurntPancake::SetSize(int S)
{
	size = S;

}


I don't see a declaration anywhere, yet that works fine.
Topic archived. No new replies allowed.