A
alariq
Hello, All
Let me describe my problem:
I have
1) base class Base
2) derived from Base template class DB (which contains other template
class Inner)
3) derived from template class DB template class DD
I want to use DB::Inner in DD
it works using Microsoft Visual C compiler, but does not work when
using G++ (i am trying to compile it for PS3)
here is the code (i've extracted it from my main program so you may
run it and see if you want)
----------------
main.cpp
---------------
#include "cmd.h"
void f1(int i)
{
return;
}
int main(int argc, const char** argv)
{
typedef void (*fptr)( int);
IO_Cmd1<void, int>* pcmd = new IO_Cmd1<void, int>("name", f1);
}
-----------------
------------------
cmd.h
------------------
#include <string>
#include <vector>
class IO_Base_Command {
protected:
const std::string m_name;
IO_Base_Command(const std::string& name):
m_name(name)
{
}
// Variant class to represent command line parameters
class Variant {
int m_i;
float m_f;
enum eType { T_INT, T_FLOAT };
eType type;
public:
// constructors
explicit Variant(int i):m_i(i),m_f(0.0f) { type = T_INT; }
explicit Variant(float f):m_f(f),m_i(0) { type = T_FLOAT; }
// cast operators
operator int () const
{
return type == T_INT ? m_i : (int)m_f;
}
operator float () const
{
return type == T_INT ? (float)m_i : m_f;
}
};
public:
const std::string getName() const { return m_name; }
virtual bool runCommand(std::vector<IO_Base_Command::Variant>&
params) = 0;
virtual ~IO_Base_Command() {};
};
//======================== IO_Cmd1
==============================================================================
//
=================================================================================================================
template <typename R, typename T>
class IO_Cmd1: public IO_Base_Command {
protected:
typedef R (*FP_t)(T);
typedef T firstParam_t;
typedef R returnValue_t;
FP_t m_func_ptr;
// default realisation, to be overriden in derived classes if
needed
template <typename RetVat_type, typename FP_type>
class doCmd {
public:
static void doCommand(FP_type func_ptr, const T param1) {
RetVat_type retval = func_ptr(param1);
}
};
template <typename FP_type>
class doCmd<void, FP_type> {
public:
static void doCommand(FP_type func_ptr, const T param1) {
func_ptr(param1);
}
};
public:
IO_Cmd1(const std::string& name, FP_t fp):
IO_Base_Command(name), m_func_ptr(fp) { }
bool runCommand(std::vector<IO_Base_Command::Variant>& params)
{
doCmd<returnValue_t, FP_t>::doCommand(m_func_ptr, params[0]);
return true;
}
};
template <typename R, typename UD>
class IO_CmdUD: public IO_Cmd1<R, UD> {
protected:
//using IO_Cmd1<R, UD>::doCmd;
// using IO_Cmd1<R, UD>::template doCmd<R, IO_Cmd1<R,
UD>::FP_t>::doCommand;*/
public:
typedef R (*FP2_t)(UD);
typedef void (*vfptr)(int);
typedef IO_Cmd1<R, UD> Parent_t;
typedef typename IO_Cmd1<R, UD>::firstParam_t UserData_t;
UserData_t m_userValue;
IO_CmdUD(const std::string& name, typename Parent_t::FP_t fp,
UserData_t userValue):
IO_Base_Command(name, fp)
, m_userValue(userValue)
{
}
bool runCommand(std::vector<IO_Base_Command::Variant>& params)
{
doCmd<R, FP2_t>::doCommand(m_func_ptr, m_userValue); // THIS
DOES NOT COMPILES
return true;
}
};
-----------------------------------
here is what compiler says:
In member function 'bool IO_CmdUD<R,
UD>::runCommand(std::vector<IO_Base_Command::Variant,
std::allocator<IO_Base_Command::Variant> >&)':
error: 'doCmd' was not declared in this scope
error: expected primary-expression before ',' token
error: expected primary-expression before '>' token
error: '::doCommand' has not been declared
error: 'm_func_ptr' was not declared in this scope
Thanks in advance for any help!
Let me describe my problem:
I have
1) base class Base
2) derived from Base template class DB (which contains other template
class Inner)
3) derived from template class DB template class DD
I want to use DB::Inner in DD
it works using Microsoft Visual C compiler, but does not work when
using G++ (i am trying to compile it for PS3)
here is the code (i've extracted it from my main program so you may
run it and see if you want)
----------------
main.cpp
---------------
#include "cmd.h"
void f1(int i)
{
return;
}
int main(int argc, const char** argv)
{
typedef void (*fptr)( int);
IO_Cmd1<void, int>* pcmd = new IO_Cmd1<void, int>("name", f1);
}
-----------------
------------------
cmd.h
------------------
#include <string>
#include <vector>
class IO_Base_Command {
protected:
const std::string m_name;
IO_Base_Command(const std::string& name):
m_name(name)
{
}
// Variant class to represent command line parameters
class Variant {
int m_i;
float m_f;
enum eType { T_INT, T_FLOAT };
eType type;
public:
// constructors
explicit Variant(int i):m_i(i),m_f(0.0f) { type = T_INT; }
explicit Variant(float f):m_f(f),m_i(0) { type = T_FLOAT; }
// cast operators
operator int () const
{
return type == T_INT ? m_i : (int)m_f;
}
operator float () const
{
return type == T_INT ? (float)m_i : m_f;
}
};
public:
const std::string getName() const { return m_name; }
virtual bool runCommand(std::vector<IO_Base_Command::Variant>&
params) = 0;
virtual ~IO_Base_Command() {};
};
//======================== IO_Cmd1
==============================================================================
//
=================================================================================================================
template <typename R, typename T>
class IO_Cmd1: public IO_Base_Command {
protected:
typedef R (*FP_t)(T);
typedef T firstParam_t;
typedef R returnValue_t;
FP_t m_func_ptr;
// default realisation, to be overriden in derived classes if
needed
template <typename RetVat_type, typename FP_type>
class doCmd {
public:
static void doCommand(FP_type func_ptr, const T param1) {
RetVat_type retval = func_ptr(param1);
}
};
template <typename FP_type>
class doCmd<void, FP_type> {
public:
static void doCommand(FP_type func_ptr, const T param1) {
func_ptr(param1);
}
};
public:
IO_Cmd1(const std::string& name, FP_t fp):
IO_Base_Command(name), m_func_ptr(fp) { }
bool runCommand(std::vector<IO_Base_Command::Variant>& params)
{
doCmd<returnValue_t, FP_t>::doCommand(m_func_ptr, params[0]);
return true;
}
};
template <typename R, typename UD>
class IO_CmdUD: public IO_Cmd1<R, UD> {
protected:
//using IO_Cmd1<R, UD>::doCmd;
// using IO_Cmd1<R, UD>::template doCmd<R, IO_Cmd1<R,
UD>::FP_t>::doCommand;*/
public:
typedef R (*FP2_t)(UD);
typedef void (*vfptr)(int);
typedef IO_Cmd1<R, UD> Parent_t;
typedef typename IO_Cmd1<R, UD>::firstParam_t UserData_t;
UserData_t m_userValue;
IO_CmdUD(const std::string& name, typename Parent_t::FP_t fp,
UserData_t userValue):
IO_Base_Command(name, fp)
, m_userValue(userValue)
{
}
bool runCommand(std::vector<IO_Base_Command::Variant>& params)
{
doCmd<R, FP2_t>::doCommand(m_func_ptr, m_userValue); // THIS
DOES NOT COMPILES
return true;
}
};
-----------------------------------
here is what compiler says:
In member function 'bool IO_CmdUD<R,
UD>::runCommand(std::vector<IO_Base_Command::Variant,
std::allocator<IO_Base_Command::Variant> >&)':
error: 'doCmd' was not declared in this scope
error: expected primary-expression before ',' token
error: expected primary-expression before '>' token
error: '::doCommand' has not been declared
error: 'm_func_ptr' was not declared in this scope
Thanks in advance for any help!