print function not working

J

j_depp_99

Could someone check my code as to why my print function is not
working? Also my pop member function is getting an error in main.
<code>

template<class Type>
void Novice<Type>::print()
{
while(! IsEmpty())
{
std::cout << topPtr->item;
topPtr = topPtr ->next;
}
}

template<class Type>
void Novice<Type>::pop(Type &y)
{
if(IsEmpty())
throw EmptyStack();
else
{
Node<Type> *tempPtr;
tempPtr = topPtr;
topPtr = topPtr -> next;
delete tempPtr;
}

}
// main function

int main()
{
Novice<int> a;

a.Pop(); // not working
a.Push(1);
a.Push(2);
a.Push(3);

cout << a.length() << endl;
a.Pop();
cout << a.length() << endl;
a.Print();
}
</code>

The compilation error: 13 H:no matching function for call to
`Novice<int>::pop()'
 
O

Obnoxious User

(e-mail address removed) skrev:
Could someone check my code as to why my print function is not
working? Also my pop member function is getting an error in main.
<code>

template<class Type>
void Novice<Type>::print()
{
while(! IsEmpty())
{
std::cout << topPtr->item;
topPtr = topPtr ->next;
}

Can't see any definition for IsEmpty() in your published code.
}

template<class Type>
void Novice<Type>::pop(Type &y)

LOOK HERE!-------->>>^^^^^^^^^^^^
{
if(IsEmpty())
throw EmptyStack();
else
{
Node<Type> *tempPtr;
tempPtr = topPtr;
topPtr = topPtr -> next;
delete tempPtr;
}

}
// main function

int main()
{
Novice<int> a;

a.Pop(); // not working
a.Push(1);
a.Push(2);
a.Push(3);

cout << a.length() << endl;
a.Pop();
cout << a.length() << endl;
a.Print();
}
</code>

The compilation error: 13 H:no matching function for call to
`Novice<int>::pop()'

There is no Novice<int>::pop(), just as the error message says.
 
J

j_depp_99

The compilation error: 13 H:no matching function for call to
`Novice<int>::pop()'

There is no Novice<int>::pop(), just as the error message says.

How do I pass the address of the top node to the calling function?
here is the IsEmpty function.
<code>
template<class Type>
bool Novice<Type>::IsEmpty()
{
return (topPtr == -1);
}
</code>
 
O

Obnoxious User

(e-mail address removed) skrev:
The compilation error: 13 H:no matching function for call to
`Novice<int>::pop()'

There is no Novice<int>::pop(), just as the error message says.

How do I pass the address of the top node to the calling function?
here is the IsEmpty function.
<code>
template<class Type>
bool Novice<Type>::IsEmpty()
{
return (topPtr == -1);
}
</code>

What do you think will equal -1?
 
J

j_depp_99

It was supposed to be:
<code>

....
return (topPtr == NULL);
</code>

About the pop() function. What do I pass to it to make it work?
 
O

Obnoxious User

(e-mail address removed) skrev:
It was supposed to be:
<code>

...
return (topPtr == NULL);
</code>

You should copy and paste code instead.
About the pop() function. What do I pass to it to make it work?

Hint:

#include <ostream>
struct s {
int i;
};
void f(s & o) {
o.i = 3;
}
int main() {
s p;
f(p);
std::cout<<p.i<<std::endl;
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,273
Latest member
DamonShoem

Latest Threads

Top