template und strings



  • Hallo,

    Ich möchte folgende Digraph Klasse auch mit strings benutzen. Mit ints und chars funktiont sie problemlos.

    Digraph<string, 5> g;
    g.InsertVertex(0,"AB");
    

    In der Klasse:

    template <class TV, int maxNodes>
    
    Digraph() { // Konstruktor
            numvertices = 0;
            numarcs = 0;
            for (int i = 0; i < maxNodes; i++) {
                for (int b = 0; b < maxNodes; b++) {
                    arc[i][b] = noArc;
                }
            }
        }
    

    Fehlermeldung
    Digraph.h:35: instantiated from ‘Digraph<TV, maxNodes>::Digraph() [with TV = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int maxNodes = 5]’
    main.cpp:15: instantiated from here
    Digraph.h:19: error: ambiguous overload for ‘operator=’ in ‘((Digraph<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, 5>::Vertex*)this)->Digraph<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, 5>::Vertex::value = 0’
    /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/basic_string.h:494: note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
    /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/basic_string.h:502: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
    /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/basic_string.h:513: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]



  • kann es sein, dass die fehlermeldung an sich fehlt? : P

    was ist arc?
    was ist noArc?

    bb



  • sonst gibts nurnoch das als Fehlermeldung
    Digraph.h: In member function ‘void Digraph<TV, maxNodes>::DeleteVertex(int) [with TV = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int maxNodes = 5]’:
    Digraph.h:51: instantiated from ‘void Digraph<TV, maxNodes>::InsertVertex(int, TV) [with TV = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int maxNodes = 5]’
    main.cpp:16: instantiated from here
    Digraph.h:65: error: ambiguous overload for ‘operator=’ in ‘((Digraph<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, 5>)this)->Digraph<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, 5>::vertex[n].Digraph<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, 5>::Vertex::value = 0’
    /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/basic_string.h:494: note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
    /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/basic_string.h:502: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT
    ) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
    /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/basic_string.h:513: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
    make[2]: *** [build/Debug/Cygwin-Windows/main.o] Error 1

    arc ist ein int const und noArc nen 2 Dimensionales Array vom double typ



  • arc ist ein int const und noArc nen 2 Dimensionales Array vom double typ

    sorry umgekehrt

    noArc ist ein int const und arc nen 2 Dimensionales Array vom double typ



  • // edit: Wunderbar, zu spät 😛

    Digraph.h: In member function ‘void Digraph<TV, maxNodes>::DeleteVertex(int) [with TV = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int maxNodes = 5]’:
    Digraph.h:51: instantiated from ‘void Digraph<TV, maxNodes>::InsertVertex(int, TV) [with TV = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int maxNodes = 5]’
    main.cpp:16: instantiated from here
    Digraph.h:65: error: ambiguous overload for ‘operator=’ in ‘((Digraph<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, 5>*)this)->Digraph<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, 5>::vertex[n].Digraph<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, 5>::Vertex::value = 0’
    /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/basic_string.h:494: note: candidates are: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
    /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/basic_string.h:502: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(const _CharT*) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
    /usr/lib/gcc/i686-pc-cygwin/4.3.4/include/c++/bits/basic_string.h:513: note: std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]
    make[2]: *** [build/Debug/Cygwin-Windows/main.o] Error 1
    

    Jetzt kann mans besser lesen.
    Relevanten Code hast du leider nicht gepostet.
    Oben Zeile 4 zeigt dir den Fehler:

    [...]Vertex::value = 0
    

    Was ist Vertex::value? Zeigst du uns mal die Klassendefinition von Digraph und Vertex?
    Am besten wäre allerdings ein minimales Beispiel, das deinen Fehler beinhaltet. Dann kann man mehr sagen.


Log in to reply