Errors, bugs, questions - page 2006

 
fxsaber:

Why should both compile?

In general, I use templates rarely - I did not go into details - I can only explain on an intuitive level

In the 2nd case, a direct replacement of T by A* compiles well - so the template should compile as well

class A {};
void f( A * const ) {}
void OnStart()
{
        A *a;
        f( a ); //нормально
}

In the 1st case, a direct substitution does not work, but you can add the redundant parameter T2 - with it compiles normally - so it should without it - for this is redundant

template<typename T, typename T2>
void f( T, const T2 ) {}
class A {};
void OnStart()
{
        const A *a;
        f( a, a ); //нормально
}
 
A100:

Intuitively, const is sometimes part of a type and sometimes just an identifier, that inside the function the pointer will be const.

This can be felt throughPrint(__FUNCSIG__);

 
The drawdown value in the optimisation table is oddly displayed. It shows maximal drawdown by means (but it is written as percentage). But after a single test it turns out that the relative drawdown differs from the maximal one (the percentage is larger or smaller). When using money management, is it necessary to add something to display the required results?
 
A100:

Compilation error

template<typename T>
void f( T, const T ) {}
class A {};
void OnStart()
{
        A * const a = new A;
        f( a, a ); //error: 'a' - cannot convert from const pointer to nonconst pointer
}
That's how it compiles, the original version shouldn't.
 
Комбинатор:
That's how it compiles, the original version should not.

Why?

template<typename T>
struct B {
        void f( T, const T ) {}
};
class A {};
void OnStart()
{
          const A* a;
        B<const A*> b;
        b.f( a, a ); //нормально
}

So it's fine. What has changed in principle?

template<typename T>
        void f( T, const T ) {}
class A {};
void OnStart()
{
          const A *a;
          f( a, a ); //error: 'a' - cannot convert from const pointer to nonconst pointer
}
 
A100:

What has changed fundamentally?

The difference is enormous! That's what you called in.

void B<const A*>::f(const A*,const A*)
The compiler bugs in the sense that it can't figure out the correct version of the template. Obviously told it to.
template<typename T>
        void f( T, const T ) {}
class A {};
void OnStart()
{
          const A *a;
          f<const A*>( a, a );
}

And it's working.

 
fxsaber:
And it's working.

Why the extra characters?

 
A100:

Why the extra characters?

To show that the compiler doesn't guess at a perfectly workable version of the pattern.

 
fxsaber:

To show that the compiler does not guess at a perfectly workable version of the pattern.

Why should it? ServiceDesk can figure it out on its own

 
A100:

Why?

Judging by your specialization, the type should have const discarded, which it does. If you explicitly specify the correct type, of course it will compile.
Reason: