Frage

Ich versuche herauszufinden, ob dies eine Voraussetzung von ist Müsli oder nicht.

Ich bekomme immer wieder Fehler, dass Klassenkonstruktoren (Standard) privat sind, was ich aus einem bestimmten Grund dort gegeben habe.

Die Ursprungslinie für den Fehler scheint jedoch eher std :: make_shared als Müsli zu sein, was einen Standardkonstruktor erfordert, aber bereits eine Freundschaftsklasse ist und daher Zugriff darauf haben sollte.

/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

Kann mir bitte jemand erklären, warum dies geschieht und was noch wichtiger ist, wie es gelöst werden könnte, abgesehen davon, dass diese Konstrukteure veröffentlicht werden?

BEARBEITEN:

Die Ursprungsfehlerlinie stammt aus:

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

Wo semanticgraph ctor ist:

    SemanticGraph
    (
      const std::string filename
    )
    : 
      _fname ( filename )
    {
      std::ifstream input( _fname );
      if ( input.is_open() )
      {
       cereal::XMLInputArchive archive( input );
       archive( _nodes );
      }
    }
War es hilfreich?

Lösung

C ++ wurde verwendet, um die Zugriffskontrolle bei Instanziierung von Vorlagen nicht in Betracht zu ziehen, außer wenn dies bei Bedarf einen Fehler erzeugt. Der Compiler, den Sie verwenden, verwendet diese Regeln immer noch. Aus diesem Grund wird Ihre Klasse nicht als nicht default-konstruktiv angesehen. Stattdessen ist der Scheck selbst unmöglich.

GCC 4.8 und höher unterstützen dies. Ein einfaches Demonstrationsprogramm, das mit 4.8 erfolgreich ist und mit 4.7 fehlschlägt, lautet:

#include <type_traits>

class S { S() {} };

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

In 4,8 kehrt dies 0 zurück. In 4,7 erzeugt dies einen Kompilierungs-Zeitfehler.

Um dies zu beheben, stellen Sie sicher, dass Sie keinen Standardkonstruktor haben, nicht einmal einen privaten. Sie können Ihrem Konstruktor ein Dummy -Argument hinzufügen und dieses Dummy -Argument immer bestehen.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top