Du bist nicht angemeldet.

Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!

Werbeanzeige

Das Gurke

Community-Fossil

  • »Das Gurke« ist der Autor dieses Themas

Beiträge: 1 996

Wohnort: Pinneberg

Beruf: Schüler

  • Private Nachricht senden

31

24.03.2008, 12:58

So einfach ging das leider nicht :( GCC sagt dazu:

Quellcode

1
2
3
Output.h:21: error: expected nested-name-specifier before "int_type"
Output.h:21: error: `int_type' does not name a type
Output.h:21: error: (perhaps `typename std::basic_streambuf<_CharT, _Traits>::int_type' was intended)

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

32

24.03.2008, 13:11

Eh, eher so:

C-/C++-Quelltext

1
virtual std::basic_streambuf< _elem, _traits >::int_type ...


Zum Problem:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
virtual int_type overflow( int_type c = _traits::eof() )
    {
        if (_traits::eq_int_type(c, _traits::eof()))
            return _traits::not_eof(c);
        const char cc = _traits::to_char_type( c );
        return (_traits::eq_int_type( m_first->sputc(cc), _traits::eof() )
            || _traits::eq_int_type( m_second->sputc(cc), _traits::eof() ))? _traits::eof(): _traits::not_eof(c);
    } 
@D13_Dreinig

Das Gurke

Community-Fossil

  • »Das Gurke« ist der Autor dieses Themas

Beiträge: 1 996

Wohnort: Pinneberg

Beruf: Schüler

  • Private Nachricht senden

33

24.03.2008, 13:25

Vorab: DANKE! Die Ausgabe ansich funktioniert nun. In der Version mit dem "normalen" int_type geht für Vc++ auch alles wunderbar. Aber leider ist da noch der gcc :(

Wenn ich das "int_type" wie von dir vorgeschlagen auflöse, hauen mich sowohl VC++ als auch der gcc mit Fehlern. Am Rande: Der "Vorschlag" vom gcc löst das Problem auch nicht, das hatte ich schon länger probiert (aber nie hier erwähnt).

Dann noch eine allgemeine Frage: int_type taucht in der Methode sowohl als Rückgabetyp als auch als Parametertyp auf. Ich gehe davon aus, dass ich beide ersetzen soll? So sieht der Code gerade bei mir aus:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
virtual std::basic_streambuf< _elem, _traits >::int_type overflow( std::basic_streambuf< _elem, _traits >::int_type c = _traits::eof() )
        {
            if (_traits::eq_int_type(c, _traits::eof()))
                return _traits::not_eof(c);
            const char cc = _traits::to_char_type( c );
            return (_traits::eq_int_type( m_first->sputc(cc), _traits::eof() )
                || _traits::eq_int_type( m_second->sputc(cc), _traits::eof() ))? _traits::eof(): _traits::not_eof(c);
        }

Fehler vom VS:

Quellcode

1
2
3
4
5
6
7
8
Warnung 1   warning C4346: 'std::basic_streambuf<_Elem,_Traits>::int_type': Abhängiger Name ist kein Typ
Fehler  2   error C2146: Syntaxfehler: Fehlendes ';' vor Bezeichner 'overflow'
Warnung 3   warning C4346: 'std::basic_streambuf<_Elem,_Traits>::int_type': Abhängiger Name ist kein Typ
Fehler  4   error C2061: Syntaxfehler: Bezeichner 'int_type'
Fehler  5   error C2059: Syntaxfehler: ')'
Fehler  6   error C2143: Syntaxfehler: Es fehlt ')' vor '{'
Fehler  7   error C4430: Fehlender Typspezifizierer - int wird angenommen. Hinweis: "default-int" wird von C++ nicht unterstützt.
Warnung 8   warning C4183: 'overflow': Rückgabetyp fehlt; Memberfunktion, die 'int' zurückgibt wird angenommen

Und vom gcc

Quellcode

1
2
3
4
Output.h:22: error: ISO C++ forbids declaration of `int_type' with no type
Output.h:22: error: cannot declare member `std::basic_streambuf<_CharT, _Traits>::int_type' within `WoRD::Output<_elem, _traits>'
Output.h:22: error: expected `;' before "overflow"
Output.h:30: error: expected `;' before "public"

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

34

24.03.2008, 13:34

Bitte:

C-/C++-Quelltext

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <streambuf>

namespace log
{
    template<typename _elem, typename _traits = std::char_traits<_elem> >
    class basic_dualstreambuf : public std::basic_streambuf<_elem, _traits >
    {
        std::basic_streambuf<_elem, _traits>*        m_first;
        std::basic_streambuf<_elem, _traits>*        m_second;

        typedef typename std::basic_streambuf< _elem, _traits >::int_type int_type;
        typedef typename std::basic_streambuf< _elem, _traits >::traits_type traits_type;

    protected:
        virtual int_type overflow( int_type c = _traits::eof() )
    {
        if (_traits::eq_int_type(c, _traits::eof()))
            return _traits::not_eof(c);
        const char cc = _traits::to_char_type( c );
        return (_traits::eq_int_type( m_first->sputc(cc), _traits::eof() )
            || _traits::eq_int_type( m_second->sputc(cc), _traits::eof() ))? _traits::eof(): _traits::not_eof(c);
    }

    public:
        explicit basic_dualstreambuf (std::basic_streambuf<_elem, _traits>* ptr_first, std::basic_streambuf<_elem, _traits>* ptr_second)
            : m_first(ptr_first), m_second(ptr_second)
        {}
    };

    typedef basic_dualstreambuf<char> dualstreambuf;
    typedef basic_dualstreambuf<wchar_t> wdualstreambuf;
} // log
@D13_Dreinig

Das Gurke

Community-Fossil

  • »Das Gurke« ist der Autor dieses Themas

Beiträge: 1 996

Wohnort: Pinneberg

Beruf: Schüler

  • Private Nachricht senden

35

24.03.2008, 13:43

Wow! Komplett vorgekaut, was für ein Service. GCC und VC++ können damit nun beide was anfangen, DANKE!

Ich hab aber doch noch eine Frage :oops: Und zwar ging ich davon aus, dass std::endl die Ausgabe auch flushed. Sollte nicht in dem Augenblick auch die Datei geschrieben werden? Momentan landet der Inhalt nämlich erst in der Datei, wenn ich das Programm beende. Oder verhalten sich Filestreams da anders?

David_pb

Community-Fossil

Beiträge: 3 886

Beruf: 3D Graphics Programmer

  • Private Nachricht senden

36

24.03.2008, 13:49

Da fehlt noch was...

C-/C++-Quelltext

1
2
virtual int sync()
    { return (m_first->pubsync() == 0 && m_second->pubsync() == 0? 0: -1); }
@D13_Dreinig

Werbeanzeige