• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Const structure pointer as template argument
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Const structure pointer as template argument


  • Subject: Re: Const structure pointer as template argument
  • From: Ladd Van Tol <email@hidden>
  • Date: Fri, 30 Jun 2006 09:05:16 -0700


On Jun 30, 2006, at 1:55 AM, Paul Walmsley wrote:

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;

Nope, the code in question needs the actual instance.

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);

Yes, this is how I would have written it, but it's a large legacy source base, and changing it is not an option.


Also, the construct I described appears to compile in CodeWarrior and Visual Studio. Not always the best indicator of standards compliance, but there you have it.

- Ladd

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Const structure pointer as template argument
      • From: David Fang <email@hidden>
References: 
 >Const structure pointer as template argument (From: Ladd Van Tol <email@hidden>)
 >Re: Const structure pointer as template argument (From: Paul Walmsley <email@hidden>)

  • Prev by Date: Re: XCODE choose system's EXPAT instead of my. Argh....
  • Next by Date: Re: Const structure pointer as template argument
  • Previous by thread: Re: Const structure pointer as template argument
  • Next by thread: Re: Const structure pointer as template argument
  • Index(es):
    • Date
    • Thread