C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Protocol template fails in Xcode. Is there a better solution

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
steve@walkereffects.com
Guest





PostPosted: Mon Nov 28, 2005 4:36 pm    Post subject: Protocol template fails in Xcode. Is there a better solution Reply with 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 <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





PostPosted: Mon Nov 28, 2005 4:50 pm    Post subject: Re: Protocol template fails in Xcode. Is there a better solu Reply with quote



[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





PostPosted: Mon Nov 28, 2005 6:07 pm    Post subject: Re: Protocol template fails in Xcode. Is there a better solu Reply with quote



That is a tremendous help!!!! Thank you!

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.