3

次のコードを検討してください。

#include <vector>
#include <boost/variant.hpp>

struct foo;

typedef boost::variant<foo> bar;

struct foo
{
    std::vector<bar> baz;
};

int main ()
{
    foo f;
    return 0;
}

Xcode 4.4 を使用した Mac OS X でのビルド (Homebrew 経由でブースト 1.50.0 をインストールしました):

  • clang++ test.cc: エラーなし。
  • clang++ -stdlib=libc++ test.cc: エラーなし。
  • clang++ -std=c++11 test.cc: エラーなし。
  • clang++ -std=c++11 -stdlib=libc++ test.cc:たくさんのエラー!

 

/usr/local/include/boost/type_traits/has_nothrow_constructor.hpp:24:40: error: incomplete type 'foo' used in type trait expression
   BOOST_STATIC_CONSTANT(bool, value = BOOST_HAS_NOTHROW_CONSTRUCTOR(T));
                                       ^
...snip...
test.cc:10:19: note: in instantiation of template class '...snip...' requested here
        std::vector<bar> baz;
                         ^
test.cc:8:8: note: definition of 'foo' is not complete until the closing '}'
struct foo
       ^

/usr/local/include/boost/mpl/next_prior.hpp:31:22: error: type 'int' cannot be used prior to '::' because it has no members
    typedef typename T::next type;
                     ^
test.cc:10:19: note: in instantiation of template class '...snip...' requested here
        std::vector<bar> baz;
                         ^

/usr/local/include/boost/mpl/sizeof.hpp:27:20: error: invalid application of 'sizeof' to an incomplete type 'foo'
    : mpl::size_t< sizeof(T) >
                   ^~~~~~~~~

test.cc:10:19: note: in instantiation of template class '...snip...' requested here
        std::vector<bar> baz;
                         ^
test.cc:8:8: note: definition of 'foo' is not complete until the closing '}'
struct foo
       ^

...big snip...

8 errors generated.

何が起きてる?指定したオプションでこれをコンパイルできないのはなぜですか? これを解決する方法はありますか?

4

2 に答える 2

5

boost::recursive_wrapper<foo>は、バリアントが実際にfoo.

于 2012-08-27T16:39:58.117 に答える
1

不完全な型をテンプレート引数として再帰的に使用することはできません。コンパイラのエラー メッセージは非常に明確です。

于 2012-08-27T07:51:57.780 に答える