Pergunta

I have an odd issue in MSVS 2010. I have a class with a function that is templitized and contains an parameter with a default value.

In my header file:

typedef unsinged int data32

class myClass
{
    private:
    ...
    public:
    ...
    template <typename T>
    T* myF(data32);
}
...

template<typename T>
T* myClass::myF(data32 size = 1)
{
    ...
}

Ok, now in my main i have something like this:

int main()
{
    myClass A;
    data32* myInt = A.myF<data32>(100);  // no complaints from pre-compiler
    data32* myInt2 = A.myF<data32>();    // pre-compiler complains "Error: no instance of the function template "myClass::myF" matches the argument list" 
}

I understand why it is unhappy as i do not have a function prototype defined for 'myF()' in the class, but shouldn't it know better? I thought the point of defaults were to make the parameters optional in the call. The code DOES compile and run just fine even thought the pre-compiler is unhappy and flags this as a problem.

Any thoughts?? Thanks!

Foi útil?

Solução

There are bugs (false alarms) in the intellisense analyzer in VS 2010. And this seems like one of them. The analyzer used for intellisense is different from the actual parser used in compiler.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top