Kodunuz, stop
başlatılması (delete
d olan) std::atomic_int
kopya kurucu kullanmak sonra, RHS üzerinde geçici std::atomic_int
inşa şöyle çalışıyor: var
std::atomic_int stop = std::atomic_int(0);
kopya-başlatma çünkü Burada yaptığınız gibi, diğer tür başlatmalara eşdeğer değildir. Burada anahtar sezgilerine, belki de aykırıdır, std::atomic_int
;
[C++11: 8.5/16]:
The semantics of initializers are as follows [..]
If the initializer is a (non-parenthesized) braced-init-list, the object or reference is list-initialized (8.5.4).
[..]
If the destination type is a (possibly cv-qualified) class type:
- If the initialization is direct-initialization, or if it is copy-initialization where the cv-unqualified version of the source type is the same class as, or a derived class of, the class of the destination, constructors are considered. The applicable constructors are enumerated (13.3.1.3), and the best one is chosen through overload resolution (13.3). The constructor so selected is called to initialize the object, with the initializer expression or expression-list as its argument(s). If no constructor applies, or the overload resolution is ambiguous, the initialization is ill-formed.
(bu neredeyse kodunuzu açıklar ama tamamen değil (bu cevabın sonunda, seçenek 3 için izin verir) 'nin kurucular sizin durumunuzda hiç dikkate alınmamaktadır)
- Otherwise (i.e., for the remaining copy-initialization cases), user-defined conversion sequences that can convert from the source type to the destination type or (when a conversion function is used) to a derived class thereof are enumerated as described in 13.3.1.4, and the best one is chosen through overload resolution (13.3). If the conversion cannot be done or is ambiguous, the initialization is ill-formed. The function selected is called with the initializer expression as its argument; if the function is a constructor, the call initializes a temporary of the cv-unqualified version of the destination type. The temporary is a prvalue. The result of the call (which is the temporary for the constructor case) is then used to direct-initialize, according to the rules above, the object that is the destination of the copy-initialization. In certain cases, an implementation is permitted to eliminate the copying inherent in this direct-initialization by constructing the intermediate result directly into the object being initialized; see 12.2, 12.8.
(Bu senaryo;! kopyası elided edilebilmesine rağmen, bu yüzden, hala mümkün olmalıdır)İşte
zaten Çözüm şudur;
direkt başlatma veya
liste başlatma kullanın: Burada alakasız
std::atomic_int stop(0); // option 1
std::atomic_int stop{0}; // option 2
std::atomic_int stop = {0}; // option 3
Şüphesiz/thread.hpp artırmak mı? Üstbilgiyi kaldırdığınızda sorun devam ediyor mu? –
Evet, destekle hiçbir ilgisi yok ... bunu neden dahil ettiğimden emin değilim! Sorun, başlık kaldırıldıktan sonra bile kalır. – Karnivaurus
[GCC 4.9'da Repro] (http://coliru.stacked-crooked.com/a/990a12fc81ea21de) –