Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Const structure pointer as template argument



Hi,
	Instances that are passed as template arguments need to be
declared with external linkage.  In your case, you need to forward
declare:

//------------ >8 snip 8<-------------------
struct testStruct {
        long a;
};

template <const testStruct* bob> class Helper { };

extern const testStruct constTestStruct;	// EXTERN DECLARE!

const testStruct constTestStruct = {0};		// static initialization
Helper<&constTestStruct> HelperConst;		// binding argument

//------------ >8 snip 8<-------------------

Now this compiles on your first example.

Otherwise static linkage (of the instance argument) may result in multiple
definitions in different translation units with the same argument name,
referring to different types (because the symbols differ).

Admittedly, the error messages in all 4.x versions of gcc could be
improved.  May I submit your testcase to gcc.gnu.org?

HTH

David



David Fang
Computer Systems Laboratory
Electrical & Computer Engineering
Cornell University
http://www.csl.cornell.edu/~fang/
	-- (2400 baud? Netscape 3.0?? lynx??? No problem!)

 _______________________________________________
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

References: 
 >Re: Const structure pointer as template argument (From: Ladd Van Tol <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.