c++ – Error a function-definition is not allowed here before { token
c++ – Error a function-definition is not allowed here before { token
You have your classes function definitions inside your main
function, which is not allowed. To fix that, you should place them outside, but to do that you will need to place the whole class outside of main as well (since you need it to be in scope):
class A
{
public:
void foo();
};
void A::foo()
{
<...>
}
int main()
{
<...>
}
Its worth noting that, while it is possible to put the whole class definition inside your main, this is not the best approach:
int main()
{
class A
{
public:
void foo()
{
<...>
}
}
}
You are missing a closing }
for the main function.
c++ – Error a function-definition is not allowed here before { token
You can use the code below:
#include <iostream>
#include <string.h>
using namespace std;
const int MAX = 50 ;
class infix
{
private :
char target[MAX], stack[MAX] ;
char *s, *t ;
int top, l ;
public :
infix() ;
void setexpr ( char *str ) ;
void push ( char c ) ;
char pop( ) ;
void convert( ) ;
int priority ( char c ) ;
void show( ) ;
};
infix::infix() //error
{
top = -1 ;
strcpy ( target, ) ;
strcpy ( stack, ) ;
l = 0 ;
}
void infix :: setexpr ( char *str )//error
{
s = str ;
// strrev ( s ) ;
l = strlen ( s ) ;
* ( target + l ) = ;
t = target + ( l - 1 ) ;
}
void infix :: push ( char c )//error
{
if ( top == MAX - 1 )
cout << nStack is fulln ;
else
{
top++ ;
stack[top] = c ;
}
}
int main()
{
/* call your function from here*/
}