Sign in to follow this  

parametrize clas template

This topic is 2337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello.
I would create a set of classes like:
[code]

class Pippo :
public CimporterBase {
public:
Pippo(){};
struct SubType{
static int n1;
};
};

and

class Pluto:
public CimporterBase{
public:
Pluto();
struct SubType{
static int n1;
};
};
[/code]

and a class:
[code]
template <typename T>
class MyClass {
public:

MyClass(){};

typename T::SubType * ptr;
static int nValue;
};
[/code]
i set some static vars:

[code]
Pippo::SubType::n1 = 1;
Pluto::SubType::n1 = 2;
[/code]

then i wish configure the MyClass class parametrize with Pippo and Pluto.
MyClass<Pippo> p
or
MyClass<Pluto> p

then
if i do in MyClass<Pippo> p
p.ptr->n1// is 1

if i do in MyClass<Pluto> p
p.ptr->n1// is 2


The problem is that i must set the MyClass in another class,
pApi->ImportEntityDS(&nEntityID, &nEntityType);//how i send an instance of MyClass to the function and get the parametrized MyClass?

in the function i think to do:

MyClass<Pippo> or MyClass<Pluto>

but it doesn't do it.
how i can parametrize the MyClass class in the other class andget the correct results?

Thanks.

Share this post


Link to post
Share on other sites
I have a hard time understand what you try to do. You know that MyClass<Pippo> and MyClass<Pluto> are two different types that has nothing in common from the type safety point of view?

Share this post


Link to post
Share on other sites
I'm not 100% sure, is this what you're looking for?
[code]
class SomeApi
{
public:
template<typename T>
void ImportEntityDS(EntityId *id, EntityType *type)
{
// Use MyClass<T>
}
};

// Somewhere
pApi->ImportEntityDS<Pluto>(&plutoId, &plutoType);

// Elsewhere
pApi->ImportEntityDS<Pippo>(&pippoId, &pippoType)
[/code]

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1311343329' post='4838903']
I'm not 100% sure, is this what you're looking for?
[code]
class SomeApi
{
public:
template<typename T>
void ImportEntityDS(EntityId *id, EntityType *type)
{
// Use MyClass<T>
}
};

// Somewhere
pApi->ImportEntityDS<Pluto>(&plutoId, &plutoType);

// Elsewhere
pApi->ImportEntityDS<Pippo>(&pippoId, &pippoType)
[/code]

thanks rip.-off but that is not the problem, is a text file importer and i have:
[code]
template<typename T>
T ImportEntityDS(EntityId *id, EntityType *type)
{
while(!eof)
if(currentline.contains(1) // i find the key 1 in the file
T = myclass<pippo>;
if(currentline.contains(12) // i find the key 12 in the file
T = myclass<pluto>;
return T;??????

i must parametrize myclass inside this function and return filled myclass
}

[/code]

Share this post


Link to post
Share on other sites

This topic is 2337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this