J
Justin Miller
Ok, I tried to make that subject as descriptive as possible.
What I'm trying to do:
I'm attempting to use policies to create a generic memento (design
pattern) template. My Memento template so far is pretty simple:
using an idea of Andrei Alexandrescu (at least that's where I first read
it) to create a lightweight way of overloading member functions since
member function specialization is not possible.
template <typename T>
struct Type2Type {
typedef T OriginalType;
};
template <typename Originator,
typename CmdObj,
typename StorageType>
class Memento
{
public:
friend Memento Originator::CreateMemento(Type2Type<CmdObj>);
//other junk
};
My point in doing this is to force a compile-time check that Originator
has a CreateMemento function that takes an argument of type Type2Type<T>.
The main reason I decided to make just the member function CreateMemento a
friend is because a statement like this:
friend class Originator; //or this...
friend Originator;
is illegal in c++. If it's an entire class we're making a friend, the
friend syntax specifies that you have to include the word 'class.'
However, in this case, adorning the template parameter Originator, with
the word 'class,' is illegal (I forget the exact reason, but regardless,
not the point).
The problem:
I instantiate this template like this:
typedef Memento<DataContainer, DataCmdObj, std::vector<SpectralData*> >
DataMemento;
When I compile this with Sun Workshop 7, it results in an error, saying
that in the friend declaration above:
friend Memento Originator::CreateMemento(Type2Type<CmdObj>);
CmdObj is not defined. This really doesn't seem like it should be a
problem. Any thoughts here?!
Could it be a problem with forward declarations vs. the need for the whole
interface to be visible?
This has been bugging me big time, so any help is appreciated.
Justin
-----------------------------------------
Programmer/Analyst
NASA/Goddard Space Flight Center Code 660
email: (e-mail address removed)
office: 301-286-9261
What I'm trying to do:
I'm attempting to use policies to create a generic memento (design
pattern) template. My Memento template so far is pretty simple:
using an idea of Andrei Alexandrescu (at least that's where I first read
it) to create a lightweight way of overloading member functions since
member function specialization is not possible.
template <typename T>
struct Type2Type {
typedef T OriginalType;
};
template <typename Originator,
typename CmdObj,
typename StorageType>
class Memento
{
public:
friend Memento Originator::CreateMemento(Type2Type<CmdObj>);
//other junk
};
My point in doing this is to force a compile-time check that Originator
has a CreateMemento function that takes an argument of type Type2Type<T>.
The main reason I decided to make just the member function CreateMemento a
friend is because a statement like this:
friend class Originator; //or this...
friend Originator;
is illegal in c++. If it's an entire class we're making a friend, the
friend syntax specifies that you have to include the word 'class.'
However, in this case, adorning the template parameter Originator, with
the word 'class,' is illegal (I forget the exact reason, but regardless,
not the point).
The problem:
I instantiate this template like this:
typedef Memento<DataContainer, DataCmdObj, std::vector<SpectralData*> >
DataMemento;
When I compile this with Sun Workshop 7, it results in an error, saying
that in the friend declaration above:
friend Memento Originator::CreateMemento(Type2Type<CmdObj>);
CmdObj is not defined. This really doesn't seem like it should be a
problem. Any thoughts here?!
Could it be a problem with forward declarations vs. the need for the whole
interface to be visible?
This has been bugging me big time, so any help is appreciated.
Justin
-----------------------------------------
Programmer/Analyst
NASA/Goddard Space Flight Center Code 660
email: (e-mail address removed)
office: 301-286-9261