I keep getting an error saying that I am not using an object while calling a method, but I do not see how i this is the issue since I declare my class as a class... here is my code:

#ifndef __STACK_H
#define __STACK_H
#include <iostream>
#include <cstdlib> 

using namespace std;


class Stack{
	public:
		Stack(){top =0;}
		void clear();
		void pop(int& x);

		int pop();

		void push(int x);
		bool const isFull();
		bool const isEmpty();
	private:
		unsigned int top;
		int const static MAXSTACK = 40;
		int sValues[MAXSTACK];
};

void Stack::clear()
{
	top = 0;
}
int Stack::pop()
{
	return sValues[--top];
}
void Stack::pop(int& x)
{
	x = sValues[--top];
}
void Stack::push(int x)
{
	sValues[top++] = x;
}
bool const Stack::isFull()
{
	return top == MAXSTACK;
}
bool const Stack::isEmpty()
{
	return top == 0;
}
int main()
{
	Stack g();
	g.push(5);
	cout << g.pop();
	for(int i = 0; i < 5; i ++)
		g.push(i);
	for(int i = 0; i <5; i++)
		cout << g.pop();
	return 0;
}
#endif

and the error messages:
1>c:\users\thuggywuggy\2630\prog11\stack.cpp(53): error C2228: left of '.push' must have class/struct/union
1>c:\users\thuggywuggy\2630\prog11\stack.cpp(54): error C2228: left of '.pop' must have class/struct/union
1>c:\users\thuggywuggy\2630\prog11\stack.cpp(56): error C2228: left of '.push' must have class/struct/union
1>c:\users\thuggywuggy\2630\prog11\stack.cpp(58): error C2228: left of '.pop' must have class/struct/union

Thanks!

line 52 should be Stack g; . The reason for this is the compiler is interpreting line 52 as a function that returns a Stack and takes no arguments.

Thank you! I read a guide elsewhere that said doing so would not allow it to compile...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.