473,382 Members | 1,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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

Nov 28 '05 #1
2 2412
st***@walkereffects.com wrote:
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 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.

Nov 28 '05 #2
That is a tremendous help!!!! Thank you!

Nov 28 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Adam Coutee | last post by:
Hello, I am trying to compile some code that includes third party header files (part of a library). I keep getting an error on the templates they've defined. An example error follows: ...
3
by: Rennie deGraaf | last post by:
The attached code compiles and works properly when I comment out the declaration, definition, and invocations of the method 'eck'. With "eck" in there, g++ fails with ttest.cpp:23: template-id...
7
by: Patrick Kowalzick | last post by:
Dear all, I just wondered if it is possible to count the number of classes created via a template class at compile time. To show what I mean I post an example, which is not working but carries...
4
by: wkaras | last post by:
I would like to propose the following changes to the C++ Standard, the goal of which are to provide an improved ability to specify the constraints on type parameters to templates. Let me say from...
0
by: Jeffrey E. Forcier | last post by:
Hoping at least some of you use XCode... In futzing with PyObjC and Cocoa programming on my Mac, I've come to know XCode a little better, and am considering switching to it from my existing...
2
by: pagekb | last post by:
Hello, I'm having some difficulty compiling template classes as containers for other template objects. Specifically, I have a hierarchy of template classes that contain each other. Template...
2
by: AlexW | last post by:
Hi, I have error of compilation when I compile below template classes in xcode 2.4.1 on MacOSX10.4.8. This xcode uses GCC 4.0.1 error: there are no arguments to 'SetLeft' that depend on a...
8
by: czuvich | last post by:
Does anyone know how to in ASP.NET (VB.NET) to display the current protocol being used between a client and server? I noticed that IIS/SQL Server can use Named Pipes if TCP/IP is not available....
13
by: Peter | last post by:
VS2008 ans ASP.NET 3.5, Office 2003 What is the best way to run Excel Template from ASP.NET web page were the Excel is only installed on the client without any ActiveX? If so can someone point...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.