문제

#include <vector>
class A
{
    std::vector<int> vec;

    void swap( A & other) noexcept(noexcept(vec.swap(other.vec)))
    {
        vec.swap(other.vec);
    }

};

int main()
{
}

This code compiles under clang(3.4) but not under gcc (4.7.1). Anyone can tell me what I am doing wrong?

EDIT

gcc error message is :

error: invalid use of incomplete type ‘class A’
error: forward declaration of ‘class A’
도움이 되었습니까?

해결책

As a work around, you may use (which works for gcc 4.7.1, gcc 4.8.1 and clang 3.4):

void swap(A& other) noexcept(noexcept(std::declval<decltype(A::vec)&>().swap(std::declval<decltype(A::vec)&>())))

or

void swap(A& other) noexcept(noexcept(vec.swap(vec)))

I think the problem is other.vec...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top