Errors, bugs, questions - page 2199

 
Комбинатор:

Temporary objects are not usually deleted immediately, but at the end of the context. In C++, if I'm not mistaken, this is spelled out in the standard.

If you want fast deletion, control the context.

Really will have to do operator =

Thank you! SD said they are planning to fix the current behaviour, but no timeframe has been set.

 

Colour lines (levels) when previewing (did not print, but probably so in print as well) graphics for printing in black and white.


 

Terminal Bild 1795

Windows 7 64.


If I start optimization and then interrupt it after 30 minutes, the terminal hangs and there is no way to stop it.

There are 8 MetaTester64 agents in Task Manager.

After that I can't start terminal. I have to wait or reboot computer.


Is it like this for everyone?

Запуск платформы - Для продвинутых пользователей - MetaTrader 5
Запуск платформы - Для продвинутых пользователей - MetaTrader 5
  • www.metatrader5.com
По завершении установки в меню "Пуск" создается группа программ торговой платформы, а на рабочем столе дополнительно помещается ярлык программы. Используйте их для запуска. Нельзя запускать одновременно две копии платформы из одной директории. Чтобы одновременно запустить несколько копий, установите соответствующее количество программ в разные...
 
What's wrong with the forum again? The day has started and the unreal slowdown has begun. The pages load fast, then for about 30 seconds.
 
Vladimir Karputov:
What's wrong with the forum again? The day has started and the unreal slowdown has begun. Pages load fast then for about 30 seconds.
Rkn, probably... there's a problem with pushing on other services... it's like telegram works through them...
 
Compiler error
class A
{
public:
  int i;
  
  void f() const
  {
    A* Tmp = true ? &this : &this; // no problem - BUG!
//    A* Tmp = &this; // '=' - cannot convert from const pointer to nonconst pointer
    
    Tmp.i = 4;
  }
};

void OnStart()
{
  const A a;
  
  a.f();
  
  Print(a.i); // 4
}
 
Ilnur Khasanov:
rkn, I guess... There are problems with pushers on other services... it's like telegram works through them...

Being outside Russia, the website still hangs up sometimes. But I've had it for months. I'm used to it.

 
fxsaber:

Thank you! It turns out that return object and "=" when defining an object go through additional constructor.

I'd actually like to see a clear table somewhere, which cases are called constructors (and which ones), and which ones are called operators. Right now it's all at the level of intuition, and it fails, of course.

You'd better not rely too much on any specific rules, compilers are allowed to optimize such things quite freely (rvo, nrvo, copy elision, maybe some other optimizations will safely cut out unnecessary stuff). The copy constructor and "equal" operator should do the same thing (no need to put different behavior in them). There's a good approach, called "copy-and-swap idiom", if English allows, it's described in detail here https://stackoverflow.com/questioncopy-and-swap idioms/3279543/what-is-the-copy-and-swap-idiom.
In brief, you write one swap function which is used in all constructors and operators (we reduce the amount of code, and get the same behavior, which results in not worrying about what the compiler will call, cut, over-optimize).

dumb_array& operator=(dumb_array other)
{
    swap(*this, other);
    return *this;
}
dumb_array (dumb_array &&other)
{//this должен быть в валидном состоянии
    swap(*this, other);
}
dumb_array& operator=(dumb_array &&other)
{
    swap(*this, other);
    return *this;
}

"Highlighted strings raise questions. Why didn't the temporary objects crash as soon as they were used? That is, before the output of thirty. "

Correctly called questions, I think. Temporary objects should have collapsed after the colon.

ZS: I tweaked the code there a bit, as the copying constructor (not the moving one) is needed anyway. For µl the benefit is not so obvious due to lack of rvalue references.
What is the copy-and-swap idiom?
What is the copy-and-swap idiom?
  • stackoverflow.com
What is this idiom and when should it be used? Which problems does it solve? Does the idiom change when C++11 is used? Although it's been mentioned in many places, we didn't have any singular "what is it" question and answer, so here it is. Here is a partial list of places where it was previously mentioned:
 
pavlick_:

You'd better not rely too much on any specific rules, compilers are allowed quite freely to optimize such things (rvo, nrvo, copy elision, maybe some other optimizations will safely cut out unnecessary stuff). The copy constructor and "equal" operator should do the same thing (no need to put different behavior in them). There's a good approach, called "copy-and-swap idiom", if English allows, it's described in detail here https://stackoverflow.com/questions/3279543/what-is-the-copy-and-swap-idiom.
In brief, you write one swap function which is used in all constructors and operators (we reduce amount of code and get the same behavior and as a result don't worry about what compiler calls, cuts, over-optimizes).

"The highlighted lines raise questions. Why didn't the temporary objects crash as soon as they were used? That is, before the output of thirty."

Correctly called questions, I think. Temporary objects should have collapsed after the colon.

Thanks, the SD has already warned about the RVO plans.

 
Why does the script not output anything?
class A
{
public:
  A() {}
  
  template <typename T>
  void operator =( T& )
  {
    Print(__FUNCSIG__);
  }

  template <typename T>
  A( T& )
  {
    Print(__FUNCSIG__);
  }
};

A* f()
{
  return(new A);
}

void OnStart()
{
  A* a = f();
  
  A* b;
  b = f();
  
  delete a;
  delete b;
}
Reason: