[GCC-XML] another set of questions after new tests

Brad King brad.king at kitware.com
Fri Mar 18 09:47:59 EST 2005


Stefan Strasser wrote:
> Nicolas Hognon schrieb:
>> So I wrote the following code
>>
>> template <class T>
>> class RefPtr
>> {
[snip]
>> };
>>
>>
>> typedef RefPtr<Object> ObjectPtr;
>>
>> But there is no other reference to the RefPtr class.
> 
> 
> looks like gcc only instantiates the member functions if you create an 
> object from it:
> 
> int main(){ ABC<int> a; } // member functions of ABC in output
> int main(){ ABC<int> *a; } //ABC<int> in output, not its member functions

Actually C++ specifies that the class tempalte is instantiated when a 
member is accessed.  Creating an object accesses the consturctor, but 
you can just do this:

typedef RefPtr<Object>::RefPtr ObjectPtr;

and that will instantiated it immediately due to the :: syntax.

See #5 here:

http://www.gccxml.org/HTML/FAQ.html

-Brad



More information about the gccxml mailing list