S
steve
Hi,
I'm trying to use a protocol class as a template parameter. The
protocol class defines its own types and methods for working with them.
The template class uses the types defined by the protocol and various
methods, however I get errors when trying to compile this in Xcode
while in Codewarrior it works fine. I'm looking for a way to either fix
this in Xcode, or find another design solution that meets the needs of
the problem.
Here is basically what I am trying to do:
----------------------
class Protocol {
public:
typedef long type;
static type Add(type val1, type val2) { return (val1 + val2); }
};
template <typename T>
class Variable {
public:
typedef T::type type; // Error in Xcode, but works in Codewarrior
//typedef long type; // Works but is not using the template type
type GetValue() { return T::Add(1, 2); }
};
----------------------
Several errors occur in Xcode when trying to compile the above code:
error: type 'T' is not derived from type 'Variable<T>'
error: expected ';' before 'type'
error: 'type' does not name a type
error: 'class Variable<Protocol>' has no member named 'GetValue'
In the end there will be a dozen protocol classes, each defining the
same named types and static methods. The only solution I have come up
with so far that works in Xcode is to explicitly define the types in
the template, such as:
template<typename T, tyepname Ttype>
but this is less than ideal since I will have more that 2 types and the
templates get used in a lot of places.
Thanks for any help!
Steve
I'm trying to use a protocol class as a template parameter. The
protocol class defines its own types and methods for working with them.
The template class uses the types defined by the protocol and various
methods, however I get errors when trying to compile this in Xcode
while in Codewarrior it works fine. I'm looking for a way to either fix
this in Xcode, or find another design solution that meets the needs of
the problem.
Here is basically what I am trying to do:
----------------------
class Protocol {
public:
typedef long type;
static type Add(type val1, type val2) { return (val1 + val2); }
};
template <typename T>
class Variable {
public:
typedef T::type type; // Error in Xcode, but works in Codewarrior
//typedef long type; // Works but is not using the template type
type GetValue() { return T::Add(1, 2); }
};
----------------------
Several errors occur in Xcode when trying to compile the above code:
error: type 'T' is not derived from type 'Variable<T>'
error: expected ';' before 'type'
error: 'type' does not name a type
error: 'class Variable<Protocol>' has no member named 'GetValue'
In the end there will be a dozen protocol classes, each defining the
same named types and static methods. The only solution I have come up
with so far that works in Xcode is to explicitly define the types in
the template, such as:
template<typename T, tyepname Ttype>
but this is less than ideal since I will have more that 2 types and the
templates get used in a lot of places.
Thanks for any help!
Steve