explicit template function problem 
Author Message
 explicit template function problem

Hi
        I have a template class where, in some cases, some of
the functions need to be explicitly overridden. It was working
fine when I had just ONE such function, but as soon as I added
a second I got C2084:Function already has a body errors on the
second explicitly defined one.
With the code the way it is below, the DefaultFeatures function
is fine and overrides and it complains that the body for
PutElementHack is already defined.
If I switch the two definitions around in the file and make
the explicit definition of PutElementHack come first for
SafeArrayPtr<IUnknown*> then PutElementHack compiles and the
definition for DefaultFeatures fails.
Is this a VC++ 5.0 bug? I looked all over the news archives
but couldn't find anything quite like it. I moved the functions
all over the place, in the code, out of the code, all around
and still I get the same bug.

                        Roland

PS The PutElementHack is there because the ::SafeArrayPutElement
function takes a pointer to the info you are putting in EXCEPT
when it's IUNknown, IDispatch or BSTR when it takes the object
directly. I'm making a typesafe safearray pointer and so the
function PutElement(long *indices, T* pElem) has to dereference
pElem in those three cases. Thank you Microsoft for that!

Here's the code snippet...

//*******************************************************
// yes it's a smart pointer to a safearray
class SafeArrayPtr<class T>{
...
        unsigned short DefaultFeatures(void){
                return 0x0000;
        }

...

        void * PutElementHack(T** ppElem){
                return (void*)ppElem;
        }

...

Quote:
};

// explicit definitions for IUnknown*s
SafeArrayPtr<IUnknown *>::DefaultFeatures(void){
        return FADF_UNKNOWN;

Quote:
}

SafeArrayPtr<IUnknown *>::PutElementHack(IUnknown **ppElem){
        return (void*)(*ppElem);

Quote:
}

//***********************************************************


Thu, 30 Nov 2000 03:00:00 GMT  
 explicit template function problem

well to reply to my own message....

In the end I did manage to get it to compile but only when
I removed the default definitions from the class definition,
put the overrides after the class and THEN the default definitions.
It's odd - I'm sure I had a few INTERNAL COMPILER ERRORS along
the way but this is what I ended up with...

                        Roland

/************* another code fragment *************
class SafeArrayPtr<class T>{
...
        // stub only
        unsigned short DefaultFeatures(void);

...
        // stub only
        void * PutElementHack(T** ppElem);

...

Quote:
};

// explicit definitions for IUnknown*s
SafeArrayPtr<IUnknown *>::DefaultFeatures(void){
        return FADF_UNKNOWN;

Quote:
}

SafeArrayPtr<IUnknown *>::PutElementHack(IUnknown **ppElem){
        return (void*)(*ppElem);

Quote:
}

// THEN default versions of the functions
template <class T> unsigned short SafeArrayPtr<T>::DefaultFeatures(void)
{
        return 0x0000;

Quote:
}

template <class T> void * SafeArrayPtr<T>::PutElementHack(T** ppElem){
        return (void*)ppElem;
Quote:
}

> Hi
>         I have a template class where, in some cases, some of
> the functions need to be explicitly overridden. It was working
> fine when I had just ONE such function, but as soon as I added
> a second I got C2084:Function already has a body errors on the
> second explicitly defined one.
> With the code the way it is below, the DefaultFeatures function
> is fine and overrides and it complains that the body for
> PutElementHack is already defined.
> If I switch the two definitions around in the file and make
> the explicit definition of PutElementHack come first for
> SafeArrayPtr<IUnknown*> then PutElementHack compiles and the
> definition for DefaultFeatures fails.
> Is this a VC++ 5.0 bug? I looked all over the news archives
> but couldn't find anything quite like it. I moved the functions
> all over the place, in the code, out of the code, all around
> and still I get the same bug.

>                         Roland

> PS The PutElementHack is there because the ::SafeArrayPutElement
> function takes a pointer to the info you are putting in EXCEPT
> when it's IUNknown, IDispatch or BSTR when it takes the object
> directly. I'm making a typesafe safearray pointer and so the
> function PutElement(long *indices, T* pElem) has to dereference
> pElem in those three cases. Thank you Microsoft for that!

> Here's the code snippet...

> //*******************************************************
> // yes it's a smart pointer to a safearray
> class SafeArrayPtr<class T>{
> ...
>         unsigned short DefaultFeatures(void){
>                 return 0x0000;
>         }

> ...

>         void * PutElementHack(T** ppElem){
>                 return (void*)ppElem;
>         }

> ...
> };

> // explicit definitions for IUnknown*s
> SafeArrayPtr<IUnknown *>::DefaultFeatures(void){
>         return FADF_UNKNOWN;
> }

> SafeArrayPtr<IUnknown *>::PutElementHack(IUnknown **ppElem){
>         return (void*)(*ppElem);
> }

> //***********************************************************



Thu, 30 Nov 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. explicit template arguments to function templates

2. Bug with explicit function template instantiation in VS.NET

3. "member function templates with explicit specification"

4. explicit specialization of class template member function

5. Explicit instantiation of member function template

6. Compiler barf on template explicit function instantiation.

7. explicit member function template instantiation

8. explicit instantiation of a template function?

9. Compiler barf on template explicit function instantiation.

10. explicit template type for member functions

11. Explicit instantiation of template function

12. Explicit Specialization of Functions in Template Classes

 

 
Powered by phpBB® Forum Software