D
daniel.w.gelder
Hello, I am writing some code that converts one group of old obselete
classes to another newer group, like this:
Bag Convert(OldBag* b) { return Bag(b->x, b->y); }
Shag Convert(OldShag* b) { return Shag(b->z * b->m); }
Rag Convert(OldRag* b) { return Rag(); }
The conversion process is pretty simple, so it's advantageous to just
have one simple syntax like Convert(this), it helps make the code
easier to read .. i can just Convert(this) and not worry about it. I
would like to make the constructors of the new Bag, Shag, Rag, etc,
protected or private though for various reasons, which means the C
functions couldn't access them. I could make Convert an overloaded
member function of a utility class, and then have it as friends of Bag
Shag Rag, as one solution. But I would like to keep the conversion
prototypes with their classes. Is there a partial specialization
template solution? Some thing like
class Convertor
{
template <typename Old, typename New>
New Convert(Old* n);
}
And then I specialize in different places in different headers:
template <> Bag Convert(OldBag* b) { return Bag(b->x, b->y); }
// later..
template <> Shag Convert(OldShag* b) { return Shag(b->m*b->z); }
// later..
template <> Rag Convert(OldRag* b) { return Rag(); }
As you can see I'm not good with the template syntax. I just want to be
able to define overloaded functions in lots of different places in the
project.
Thanks much.
Dan
classes to another newer group, like this:
Bag Convert(OldBag* b) { return Bag(b->x, b->y); }
Shag Convert(OldShag* b) { return Shag(b->z * b->m); }
Rag Convert(OldRag* b) { return Rag(); }
The conversion process is pretty simple, so it's advantageous to just
have one simple syntax like Convert(this), it helps make the code
easier to read .. i can just Convert(this) and not worry about it. I
would like to make the constructors of the new Bag, Shag, Rag, etc,
protected or private though for various reasons, which means the C
functions couldn't access them. I could make Convert an overloaded
member function of a utility class, and then have it as friends of Bag
Shag Rag, as one solution. But I would like to keep the conversion
prototypes with their classes. Is there a partial specialization
template solution? Some thing like
class Convertor
{
template <typename Old, typename New>
New Convert(Old* n);
}
And then I specialize in different places in different headers:
template <> Bag Convert(OldBag* b) { return Bag(b->x, b->y); }
// later..
template <> Shag Convert(OldShag* b) { return Shag(b->m*b->z); }
// later..
template <> Rag Convert(OldRag* b) { return Rag(); }
As you can see I'm not good with the template syntax. I just want to be
able to define overloaded functions in lots of different places in the
project.
Thanks much.
Dan