2017-11-02 20 views
0

Visual Studio 2013에서 작동하는 데 사용하는 코드가 있습니다. Visual Studio 2017에서 동일한 코드를 작성하려고하기 때문에 불평합니다. 여기에 내가하려고하는 코드가있다. 이와 원자 C++에 대해 삭제 된 함수를 참조하려고 시도했습니다.

#include <array> 
#include <atomic> 

int main() 
{ 

    using TrdRobotStateArray = std::array<std::atomic<double>, 6>; 
    TrdRobotStateArray mCurrentPose = { 0.3 }; 
    printf("%0.3f", mCurrentPose[0]); 
    return 0; 
} 

, 나는이 오류 얻을 :이 코드를 작성하지 않은

error C2280: 'std::atomic<double>::atomic(const std::atomic<double> &)': attempting to reference a deleted function 

을, 나는 원자 변수로 읽어 것을 시도하고있다. 그러나 나는 여전히 그 오류로 어떤 일이 벌어지고 있는지 확실히 모른다. atomics에 대한 설명은 크게 감사하겠습니다. 감사!

갱신 : 여기

모든 오류 및 코드와 함께 경고입니다. 그래서 그것은 미래에 다른 사람들을 도울 것입니다.

1>AtomicTest.cpp 
1>AtomicTest.cpp(13): error C4839: non-standard use of class 
'std::atomic<double>' as an argument to a variadic function 
1>AtomicTest.cpp(13): note: the constructor and destructor will not be 
called; a bitwise copy of the class will be passed as the argument 
1>AtomicTest.cpp(11): note: see declaration of 'std::atomic<double>' 
1>AtomicTest.cpp(13): error C2280: 'std::atomic<double>::atomic(const 
std::atomic<double> &)': attempting to reference a deleted function 
1>C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\atomic(689): 
note: see declaration of 'std::atomic<double>::atomic' 
1>C:\Program Files (x86)\Microsoft Visual 
Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\include\atomic(689): 
note: 'std::atomic<double>::atomic(const std::atomic<double> &)': function 
was explicitly deleted 
1>AtomicTest.cpp(13): warning C4477: 'printf' : format string '%0.3f' 
requires an argument of type 'double', but variadic argument 1 has type 
'std::atomic<double>' 
1>Done building project "AtomicTest.vcxproj" -- FAILED. 
+0

잠깐 ... 실제로이 코드에 대한 첫 번째 오류 메시지는 '오류 C4839 : 표준 외의 클래스'std :: atomic '을 가변 인수 함수의 인수로 사용합니다.'입니다. 컴파일러를 어떻게 호출합니까? –

+0

추신 : 향상된 오류 메시지가 Visual C++ 2017의 최신 버전에 추가 된 것 같습니다. https://docs.microsoft.com/en-us/cpp/cpp-conformance-improvements-2017을 참조하십시오. 최신 버전으로 업그레이드 할 수 있습니다. –

+0

그래, 나는 그 오류도 받지만 Jodocus 수정을 적용하자마자 사라졌다. 나는 그것에 대해 걱정해야합니까? –

답변

2

당신은 컴파일하기 위해 명시 적으로 값을로드 할 수 있습니다

printf("%0.3d", mCurrentPose[0].load()); 

그렇지 않으면 명확하게 의도하지 않은) (printf와의 원자 변수 자체를 복사하려고합니다.

+0

감사합니다. 교육 목적으로. 왜'mCurrentPose [0]'이 복사 생성자를 호출합니까? 원자 물체를 사용하면 어떤 이점이 있습니까? –

+0

btw,'% f'는 float 값을 출력하는데 사용되며'mCurrentPose [0]'은 float가 아닙니다. – mnciitbhu

+0

아, 맞아, 지금 바꿨어. –

2

원자 변수는 CopyConstructible (복사 가능 생성자) 수 없습니다.

이것은 C++ 표준의 요구 사항이므로 VisualStudio 2017이 정확합니다.