473,734 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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<Protoc ol>' 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<typena me 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 2437
st***@walkereff ects.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
1639
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: "/usr/local/SensAble/GHOST/v31/include/gstGenericMatrix.h", line 115: error(1424): constant "DIMM" is not used in declaring the parameter types of function template "gstGenericMatrix::mulPointMatrix"
3
2324
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 `eck<>' for `void blah<int>::eck(int)' does not match any template declaration ttest.cpp:23: syntax error before `{' token ttest.cpp:25: syntax error before `<<' token Note that 'gak' (a template function in a template class) works, as
7
5949
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 the idea: static int counter = 0; // this variable can be changed only at runtime... template <typename T> struct want_to_be_counted;
4
2735
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 the start that my knowledge of compiler implementation is very limited. Therefore, my suggestions may have to be rejected because they are difficult or impossible to implement. The proposal is based on the concept of "type similarity". Type...
0
1493
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 editor (TextMate). However, it appears to lack your typical auto-indenting that I'm sure most of you also find indispensable, e.g. hitting Return after a 'def', 'class', 'if' etc results in an automatic indentation. Has anyone found a way to get...
2
3343
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 class B has an instance of template class A, which has some base type T (usually int or double). However, the base type T is important to calculations in B, so I would like to obtain access to the type for further variable declaration within B. ...
2
2078
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 template parameter, so a declaration of 'SetLeft' must be available error: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated) The same code compiles successfuly on VisualC++2005 Express...
8
1437
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. Does anyone know how to programmatically see which protocol is being used? Thanks.
13
2989
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 me to an example? Do not have Sharepoint. This is for Intranet and security is not important. Thank You
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8776
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2724
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.