다음을 통해 공유


컴파일러 경고(수준 3) C4839

variadic 함수에 대한 인수로 'type' 클래스의 비표준 사용

variadic 함수에 전달되는 클래스 또는 구조체(예: printf 사소한 복사 가능)여야 합니다. 해당 개체를 전달할 때 컴파일러는 비트 복사본을 만들기만 하고 생성자 또는 소멸자를 호출하지 않습니다.

이 경고는 Visual Studio 2017부터 사용할 수 있습니다.

예시

다음 샘플에서는 C4839를 생성합니다.

// C4839.cpp
// compile by using: cl /EHsc /W3 C4839.cpp
#include <atomic>
#include <memory>
#include <stdio.h>

int main()
{
    std::atomic<int> i(0);
    printf("%i\n", i); // error C4839: non-standard use of class 'std::atomic<int>'
                        // as an argument to a variadic function
                        // note: the constructor and destructor will not be called;
                        // a bitwise copy of the class will be passed as the argument
                        // error C2280: 'std::atomic<int>::atomic(const std::atomic<int> &)':
                        // attempting to reference a deleted function
}

오류를 수정하려면 일반적으로 복사 가능한 형식을 반환하는 멤버 함수를 호출하거나

    std::atomic<int> i(0);
    printf("%i\n", i.load());

CStringW을 사용하여 빌드 및 관리되는 문자열의 경우 제공된 operator LPCWSTR()를 사용하여 CStringW 개체를 서식 문자열에 필요한 C 포인터에 캐스팅해야 합니다.

    CStringW str1;
    CStringW str2;
    // ...
    str1.Format("%s", static_cast<LPCWSTR>(str2));