Errors, bugs, questions - page 1691

 
code generation error
void OnStart()
{
  int a = {0}; // code generation error
}
 
Andrey Dik:

What spread values does theCopySpread() function producefor the corresponding chart period?

It is not clear whether it is the average, minimum or maximum, and the help of the function does not say anything about it.

 
Andrey Dik:

What spread values does theCopySpread() function producefor the corresponding chart period?

It is not clear whether it is the average, minimum or maximum, and the help of the function does not say anything about it.

Where, in the account or in the tester
 
Alexander Bereznyak:
where, in the account or in the tester
neither of which is in the reference.
 

ambiguous call to overloaded function with the same parameters

class A
{
public:  
//  void func( const int ) const {} // если заменить на это - будет компилироваться
  void func( const int ) {}

//  void func( const int& ) const {} // если заменить на это - будет компилироваться
  void func( const int& ) {}
};

void OnStart()
{
  A a;

  a.func(0);  

  int i1 = 0;
  a.func(i1);  

  const int i2 = 0;
  a.func(i2); // 'func' - ambiguous call to overloaded function with the same parameters  
}

Is this a misunderstanding or a bug?

 
fxsaber:

Is it my misunderstanding or a bug?

My understanding is that this code should behave the same in both cases.
 
fxsaber:

ambiguous call to overloaded function with the same parameters

Is this a misunderstanding or a bug?

Misunderstanding.

Well, that's it, I've answered it. ))))

 
Комбинатор:
To my understanding this code must behave the same in both cases.

That's what I think too.

Sergei Vladimirov:

Misunderstanding.

Well, that's it, I've answered. ))))

That stupid source code example took a long time to create. My sense of humour almost disappeared while I was creating it.

 
fxsaber:

This dumb source example took a long time to create. My sense of humour almost disappeared while I was creating it.

(chuckles) Okay. )

In all the three versions of the call it is impossible to understand whether the argument is passed by value or by reference, so the compiler cannot choose which function to call. And the const modifier overloads them: void f(){} and void f() const {} are different functions. If in your example you declare one of the methods as const, then uncertainty will disappear: the compiler will select the desired method depending on whether the call is made from a constant object or not (the type of argument in your example does not matter).

Your object a is not a constant, so the method without const will be called all three times. If you declare an object as constant (A const a;), then a constant method will be called.

See what the output will be:

class A
{
public:  
  void func() {Print("Non const");}
  void func() const {Print("Const");}
};

void OnStart()
{
        A a;
        A const b;
        
        a.func();
        b.func();
}
 
Sergei Vladimirov:

Good. )

In all three variants of the call it is impossible to understand whether an argument is passed by value or by reference, that's why the compiler cannot choose which function to call. And the const modifier overloads them: void f(){} and void f() const {} are different functions. If in your example you declare one of the methods as const, then uncertainty will disappear: the compiler will select the desired method depending on whether the call is made from a constant object or not (the type of argument in your example does not matter).

Your object a is not a constant, so the method without const will be called all three times. If you declare the object as constant (A const a;), then the constant method will be called.

You would have run it first. The error is ONLY here
const int i2 = 0;
a.func(i2); // 'func' - ambiguous call to overloaded function with the same parameters

All calls before that go through without any problems.

See what it prints out:

This is from another thread.