문제

나는 이것이 요구 사항인지 알아 내려고 노력하고 있습니다. 시리얼 아니면 아니에요.

클래스 생성자 (기본 구성 요소)가 비공개 인 오류가 계속되고 있습니다.

그러나 오류의 원래 선은 시리얼이 아닌 std :: make_shared 인 것 같습니다. 이는 기본 생성자가 필요하지만 이미 친구 클래스이므로 액세스 할 수 있어야합니다.

/usr/include/c++/4.7/type_traits: In instantiation of ‘struct std::__is_default_constructible_impl<Concept>’:
/usr/include/c++/4.7/type_traits:116:12:   required from ‘struct std::__and_<std::__not_<std::is_void<Concept> >, std::__is_default_constructible_impl<Concept> >’
/usr/include/c++/4.7/type_traits:682:12:   required from ‘struct std::__is_default_constructible_atom<Concept>’
/usr/include/c++/4.7/type_traits:703:12:   required from ‘struct std::__is_default_constructible_safe<Concept, false>’
/usr/include/c++/4.7/type_traits:709:12:   required from ‘struct std::is_default_constructible<Concept>’
/usr/local/include/cereal/types/polymorphic.hpp:157:5:   required by substitution of ‘template<class Archive, class T> typename std::enable_if<((! std::is_default_constructible<T>::value) && (! has_load_and_allocate<T, Archive>())), bool>::type cereal::polymorphic_detail::serialize_wrapper(Archive&, std::shared_ptr<_Tp2>&, uint32_t) [with Archive = cereal::XMLInputArchive; T = Concept]’
/usr/local/include/cereal/types/polymorphic.hpp:253:5:   [ skipping 16 instantiation contexts ]
/usr/include/c++/4.7/bits/shared_ptr_base.h:525:8:   required from ‘std::__shared_count<_Lp>::__shared_count(std::_Sp_make_shared_tag, _Tp*, const _Alloc&, _Args&& ...) [with _Tp = SemanticGraph<Concept>; _Alloc = std::allocator<SemanticGraph<Concept> >; _Args = {const char (&)[16]}; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/4.7/bits/shared_ptr_base.h:997:35:   required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<SemanticGraph<Concept> >; _Args = {const char (&)[16]}; _Tp = SemanticGraph<Concept>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2u]’
/usr/include/c++/4.7/bits/shared_ptr.h:317:64:   required from ‘std::shared_ptr<_Tp>::shared_ptr(std::_Sp_make_shared_tag, const _Alloc&, _Args&& ...) [with _Alloc = std::allocator<SemanticGraph<Concept> >; _Args = {const char (&)[16]}; _Tp = SemanticGraph<Concept>]’
/usr/include/c++/4.7/bits/shared_ptr.h:599:39:   required from ‘std::shared_ptr<_Tp1> std::allocate_shared(const _Alloc&, _Args&& ...) [with _Tp = SemanticGraph<Concept>; _Alloc = std::allocator<SemanticGraph<Concept> >; _Args = {const char (&)[16]}]’
/usr/include/c++/4.7/bits/shared_ptr.h:615:42:   required from ‘std::shared_ptr<_Tp1> std::make_shared(_Args&& ...) [with _Tp = SemanticGraph<Concept>; _Args = {const char (&)[16]}]’
/home/alex/projects/Icarus/trunk/Api/ConnectionHandler/../../Processes/Controller/../../Datatypes/Domain/../../Handlers/SemanticNodeFactory/SemanticNodeFactory.hpp:34:82:   required from here
/home/alex/projects/Icarus/trunk/Api/ConnectionHandler/../../Processes/Controller/../../Datatypes/Domain/../Episode/../State/../ConceptGraph/../Concept/Concept.hpp:27:5: error: ‘Concept::Concept()’ is private

누군가가 왜 이런 일이 일어나고 있는지, 그리고 더 중요한 것은 그 생성자를 공개하는 것 외에 어떻게 해결 될 수 있습니까?

편집하다:

원래의 오류 줄은 다음과 같습니다.

concept_map  = std::make_shared<SemanticGraph<Concept>>( "concept_map.xml" );

SemanticGraph CTOR가있는 곳 :

    SemanticGraph
    (
      const std::string filename
    )
    : 
      _fname ( filename )
    {
      std::ifstream input( _fname );
      if ( input.is_open() )
      {
       cereal::XMLInputArchive archive( input );
       archive( _nodes );
      }
    }
도움이 되었습니까?

해결책

C ++는 템플릿을 인스턴스화 할 때 액세스 제어를 고려하지 않았으며 필요한 경우 오류를 생성하는 것을 제외하고는 사용되었습니다. 사용중인 컴파일러는 여전히 해당 규칙을 사용합니다. 그로 인해 수업은 기본 구성 불가능한 것으로 간주되지 않습니다. 대신 수표 자체는 불가능합니다.

GCC 4.8 이상이이를 지원합니다. 4.8로 성공하고 4.7로 실패하는 간단한 데모 프로그램은 다음과 같습니다.

#include <type_traits>

class S { S() {} };

int main() {
  return std::is_default_constructible<S>::value;
}

4.8에서 이것은 0을 반환합니다. 4.7에서 컴파일 타임 오류가 발생합니다.

이를 해결하려면 기본 생성자가 아니라 개인 생성자가 아닌지 확인하십시오. 당신은 당신의 생성자에 더미 인수를 추가하고 항상 그 더미 인수를 전달해야합니다.

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