Re: Const structure pointer as template argument
Subject : Re: Const structure pointer as template argument
From: Paul Walmsley <email@hidden >
Date: Fri, 30 Jun 2006 09:55:33 +0100
Delivered-to: email@hidden
Delivered-to: email@hidden
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.4) Gecko/20060516 Thunderbird/1.5.0.4 Mnenhy/0.7.4.0
typedef struct testStruct
{
long a;
} testStruct;
template <const testStruct * bob> class Helper
{
};
// this compiles
testStruct nonConstTestStruct = {0};
Helper<&nonConstTestStruct> HelperNonConst;
// this doesn't
const testStruct constTestStruct = {0};
Helper<&constTestStruct> HelperConst;
Unless you're trying to do something very subtle, I reckon that this is
really what you wanted to do:
struct testStruct
{
long a;
};
template <class T> class Helper
{
};
testStruct nonConstTestStruct = {0};
Helper<testStruct*> HelperNonConst;
const testStruct constTestStruct = {0};
Helper<const testStruct*> HelperConst;
If you had a need to pass a const or non-const pointer into the Helper
so that it references a testStruct, then change the definition to this:
template <class T> class Helper
{
Helper(T object) : myObject(object) {};
T myObject;
};
const testStruct constTestStruct = {0};
Helper<const testStruct*> HelperConst(&constTestStruct);
Paul
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/xcode-users/email@hidden
This email sent to email@hidden
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.