A
asd
Hello All,
I am going back to C++ after 3 years and I am struggling with it.
FYI, This topic has 2 questions.
Here is my problem. I have class, which must have a function which returns
a pointer to a function.
Here is how I did it.
/////// in .h ///////////
class Expression : public BaseType{
public:
typedef int (*int_function)(Expression *left, Expression *right, Gpl_type
type);
int_function GetIntFunction(yytokentype token);
};
/////// I tried following in .cpp ///////////
int_function Expression::GetIntFunction(yytokentype token)
{} // compiler barks since int_function is not in global scope
Expression::int_function Expression::GetIntFunction(yytokentype token)
{} // compiler barks saying that there is no int_function.
/////////////////////////////////////////////////
My first question is: Is there a way to access int_function typedef
in the cpp file?
I can not typedef int_function before the class definition because it has
a pointer to Expression class.
Since compiler did not let me use typedef outside of the scope I did
something like following:
/////// in .h ///////////
class Expression : public BaseType{
public:
int (*GetIntFunction(yytokentype token))(Expression *left, Expression
*right, Gpl_type type);
// I could not remember the original statement but it was close to this
// one and compiler said that it was ok.
};
/////// I tried following in .cpp ///////////
int (*Expression::GetIntFunction(yytokentype token))(Expression *left,
Expression *right, Gpl_type type); // compiler barks.
int (Expression::*GetIntFunction(yytokentype token))(Expression *left,
Expression *right, Gpl_type type); // compiler barks.
My second question is: How should i declare that function in the cpp file
so the compiler will not bark?
I appreciate your efforts and time for answering my silly questions.
Right now I solved the problem by using same typedef inside and after the
definition of the class. I am just trying to learn what is the proper way
of doing it.
Thanks a lot.
I am going back to C++ after 3 years and I am struggling with it.
FYI, This topic has 2 questions.
Here is my problem. I have class, which must have a function which returns
a pointer to a function.
Here is how I did it.
/////// in .h ///////////
class Expression : public BaseType{
public:
typedef int (*int_function)(Expression *left, Expression *right, Gpl_type
type);
int_function GetIntFunction(yytokentype token);
};
/////// I tried following in .cpp ///////////
int_function Expression::GetIntFunction(yytokentype token)
{} // compiler barks since int_function is not in global scope
Expression::int_function Expression::GetIntFunction(yytokentype token)
{} // compiler barks saying that there is no int_function.
/////////////////////////////////////////////////
My first question is: Is there a way to access int_function typedef
in the cpp file?
I can not typedef int_function before the class definition because it has
a pointer to Expression class.
Since compiler did not let me use typedef outside of the scope I did
something like following:
/////// in .h ///////////
class Expression : public BaseType{
public:
int (*GetIntFunction(yytokentype token))(Expression *left, Expression
*right, Gpl_type type);
// I could not remember the original statement but it was close to this
// one and compiler said that it was ok.
};
/////// I tried following in .cpp ///////////
int (*Expression::GetIntFunction(yytokentype token))(Expression *left,
Expression *right, Gpl_type type); // compiler barks.
int (Expression::*GetIntFunction(yytokentype token))(Expression *left,
Expression *right, Gpl_type type); // compiler barks.
My second question is: How should i declare that function in the cpp file
so the compiler will not bark?
I appreciate your efforts and time for answering my silly questions.
Right now I solved the problem by using same typedef inside and after the
definition of the class. I am just trying to learn what is the proper way
of doing it.
Thanks a lot.