Cannot see the class instance from main program HELP!

This is the beginning of my main program:

#include
#include
#include
#include
#include "Stack.h"
#include "Stack.cpp"

using namespace std;

template
void Menu();

template
void isBinary(const St_element &);

template
bool isPalindrome();

template
bool isExponential();

template
void Exit();

int main()
{
Menu();
return 0;

}

template
void Menu()
{
Stack inst;

inst.initializeStack();
int Choice;
do
{
cout << "OPERATIONS MENU";
.
.
.
.
---------------------------------------------------------------

The header file looks like this:

#ifndef STACK_H
#define STACK_H
#include <iostream>
#include
#include
#include

using namespace std;

ofstream salida;
const int ST_LIMIT = 40;

template
class Stack
{
public:
Stack ();
Stack(const St_element & otherStack);
void initializeStack();
St_element Tope ();
bool IsEmpty () const;
bool IsFull () const;
void Pop ();
void Push (const St_element & Value);
void Display (ofstream & salida) const ;
private:
St_element *v;
int Top;

};

#endif

------------------------------------------------------
When I run the G++ compiler it gives the following error message:

Stackmain.cpp: In function `int main()':
Stackmain.cpp:28: no matching function for call to `Menu()'
Stackmain.cpp: In function `void Menu()':
Stackmain.cpp:36: syntax error before `;' token
--------------------------------------------------------

I believe it is not seeing the header class and cannot define Stack inst.
How should I make my main program see the class declaration and function definitions?

Comments

  • : ------------------------------------------------------
    : When I run the G++ compiler it gives the following error message:
    :
    : Stackmain.cpp: In function `int main()':
    : Stackmain.cpp:28: no matching function for call to `Menu()'
    : Stackmain.cpp: In function `void Menu()':
    : Stackmain.cpp:36: syntax error before `;' token
    : --------------------------------------------------------
    :
    : I believe it is not seeing the header class and
    : cannot define Stack inst.

    The error message is not referring to the Stack class at all.

    The problem (as the error message indicates) is your call of Menu() on line 28. Menu() is a template and you didn't supply the template argument.



  • : The error message is not referring to the Stack class at all.
    :
    : The problem (as the error message indicates) is your call of Menu() on line 28. Menu() is a template and you didn't supply the template argument.
    :
    :
    :

    I thought that and changed it around but it still gives me a syntax error where I mention the Stack class instance. Also the only time it gives me error is on the Menu function call. The Exit function doesn't give me the same error message and it doesn't have an argument either. So I am stumped :(
  • : I thought that and changed it around but it still gives me a syntax error
    : where I mention the Stack class instance.

    Menu() is a template function. You need to supply the template arguments. That's it. No amount of rearranging your code is going to fix that.

    If Menu() had regular parameters the compiler might be able to deduce the template arguments, but that's not going to help here.

    : Also the only time it gives me error is on the Menu function call. The Exit
    : function doesn't give me the same error message and it doesn't have an
    : argument either. So I am stumped :(

    Can't comment on that, there's no source for me to read. But if your compiler is magically supplying random template arguments for you, there's something seriously wrong with it.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories