 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
steve@walkereffects.com Guest
|
Posted: Mon Nov 28, 2005 4:36 pm Post subject: Protocol template fails in Xcode. Is there a better solution |
|
|
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
|
|
| Back to top |
|
 |
red floyd Guest
|
Posted: Mon Nov 28, 2005 4:50 pm Post subject: Re: Protocol template fails in Xcode. Is there a better solu |
|
|
[email]steve (AT) walkereffects (DOT) com[/email] wrote:
| Quote: | 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
class Variable {
public:
typedef T::type type; // Error in Xcode, but works in Codewarrior
typedef typename T::type type;
//typedef long type; // Works but is not using the template type
type GetValue() { return T::Add(1, 2); }
};
|
The compiler doesn't know that the dependent name T::type is a type, so
you have to help it with the typename keyword.
|
|
| Back to top |
|
 |
steve@walkereffects.com Guest
|
Posted: Mon Nov 28, 2005 6:07 pm Post subject: Re: Protocol template fails in Xcode. Is there a better solu |
|
|
That is a tremendous help!!!! Thank you!
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|