template class using in derived class

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!
 
A

alariq

Thanks for the reply
But (1) then how would you suggest me to rewrite it? Remove doCmd
class to global namespace?
BTW can i specialize in namespace scope, not in class?

And (2) Why it works for IO_Cmd1::runCommand then, and does not for
derived class? I do not understand :(
 

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

Similar Threads

using my template class 11
Derived class question 9
Exceptions in class 7
Template friend in templat class 8
error in using template 1
template class 3
Template Class 4
template class with a reference parameter 1

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top