przeładowanie operatora <<

2013-06-14 10:06
0

Witam! :)

Nie potrafię rozgryźć dlaczego kod poniżej zamiast wyświetlić poprawnie zawartość danej komórki, odczytuje adres wskaźnika z pamięci (chyba.. bo dostaję coś w stylu 0x21b1d00)


ostream& operator<<(ostream& os, const BasicExcelCell& cell)
{
    switch(cell.Type())
    {
        case BasicExcelCell::UNDEFINED:
            os << '\0';
            break;

        case BasicExcelCell::INT:
            os << cell.GetInteger();
            break;

        case BasicExcelCell::DOUBLE:
            os << cell.GetDouble();
            break;

        case BasicExcelCell::STRING:
            os << cell.GetString();
            break;

        case BasicExcelCell::WSTRING:
            os << cell.GetWString();
            break;
    }

    return os;
}
    for(int y=0; y <= this->TotalRows; ++y) {
        for(int x=0; x <= this->TotalCols; ++x) {

        BasicExcelCell* cell = this->sheet->Cell(y, x);

                wcout << cell << endl;                //lub cout << cell << endl;

                this->fmt->set_background(MAKE_COLOR2(EGA_RED,0));
                cell->SetFormat(*this->fmt);

        }
    } 

Wydaje mi się, że ten przeładowany operator powinien działać, ale tak nie jest.. Why?! :(

edytowany 1x, ostatnio: Mc_Hammer, 2013-06-14 10:07

Pozostało 580 znaków

2013-06-14 10:17
0

cell to wskaźnik, żeby dostać obiekt użyj operatora dereferencji - *. Powinno być:

wcout << *cell << endl;

Dodatkowo nie powinieneś używać std::endl jedynie do przechodzenia do nowej linii - od tego jest po prostu "\n".


"(...) otherwise, the behavior is undefined".

Pozostało 580 znaków

2013-06-14 14:58
0

próbowałem, ale kompilator wyrzuca:

/home/workspace/ExcelFormat_src/specification.cpp|90|error: no match for ‘operator<<’ in ‘std::wcout << * cell’
/home/workspace/ExcelFormat_src/specification.cpp|90|note: candidates are:
...

wygląda to tak jakby kompilator nie mógł znaleźć tego przeładowanego operatora

edytowany 2x, ostatnio: Mc_Hammer, 2013-06-14 15:03
no i co masz podane w tych "candidates are"? - Azarien 2013-06-14 15:05

Pozostało 580 znaków

2013-06-15 17:37
0

nie chciałem dodawać bo sporo tego... :)

||=== ExcelFormat, Debug Win32 ===|
/home/michalzrb/workspace/ExcelFormat_src/specification.cpp||In member function ‘void specification::GetElementByName(std::string)’:|
/home/michalzrb/workspace/ExcelFormat_src/specification.cpp|90|error: no match for ‘operator<<’ in ‘std::wcout << * cell’|
/home/michalzrb/workspace/ExcelFormat_src/specification.cpp|90|note: candidates are:|
/usr/include/c++/4.6/ostream|110|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|110|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘std::basic_ostream<wchar_t>::__ostream_type& (*)(std::basic_ostream<wchar_t>::__ostream_type&) {aka std::basic_ostream<wchar_t>& (*)(std::basic_ostream<wchar_t>&)}’|
/usr/include/c++/4.6/ostream|119|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<wchar_t>]|
/usr/include/c++/4.6/ostream|119|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘std::basic_ostream<wchar_t>::__ios_type& (*)(std::basic_ostream<wchar_t>::__ios_type&) {aka std::basic_ios<wchar_t>& (*)(std::basic_ios<wchar_t>&)}’|
/usr/include/c++/4.6/ostream|129|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|129|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘std::ios_base& (*)(std::ios_base&)’|
/usr/include/c++/4.6/ostream|167|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|167|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘long int’|
/usr/include/c++/4.6/ostream|171|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|171|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘long unsigned int’|
/usr/include/c++/4.6/ostream|175|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|175|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘bool’|
/usr/include/c++/4.6/bits/ostream.tcc|93|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>]|
/usr/include/c++/4.6/bits/ostream.tcc|93|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘short int’|
/usr/include/c++/4.6/ostream|182|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|182|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘short unsigned int’|
/usr/include/c++/4.6/bits/ostream.tcc|107|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>]|
/usr/include/c++/4.6/bits/ostream.tcc|107|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘int’|
/usr/include/c++/4.6/ostream|193|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|193|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘unsigned int’|
/usr/include/c++/4.6/ostream|202|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|202|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘long long int’|
/usr/include/c++/4.6/ostream|206|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|206|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘long long unsigned int’|
/usr/include/c++/4.6/ostream|211|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|211|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘double’|
/usr/include/c++/4.6/ostream|215|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|215|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘float’|
/usr/include/c++/4.6/ostream|223|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|223|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘long double’|
/usr/include/c++/4.6/ostream|227|note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<wchar_t>]|
/usr/include/c++/4.6/ostream|227|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘const void*’|
/usr/include/c++/4.6/bits/ostream.tcc|121|note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = wchar_t, _Traits = std::char_traits<wchar_t>, std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<wchar_t>]|
/usr/include/c++/4.6/bits/ostream.tcc|121|note:   no known conversion for argument 1 from ‘YExcel::BasicExcelCell’ to ‘std::basic_ostream<wchar_t>::__streambuf_type* {aka std::basic_streambuf<wchar_t>*}’|
/usr/include/c++/4.6/bits/basic_string.h|2693|note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)|
/usr/include/c++/4.6/ostream|451|note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)|
/usr/include/c++/4.6/ostream|456|note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)|
/usr/include/c++/4.6/ostream|462|note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)|
/usr/include/c++/4.6/ostream|468|note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)|
/usr/include/c++/4.6/ostream|473|note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)|
/usr/include/c++/4.6/ostream|493|note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)|
/usr/include/c++/4.6/bits/ostream.tcc|323|note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)|
/usr/include/c++/4.6/ostream|510|note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)|
/usr/include/c++/4.6/ostream|523|note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)|
/usr/include/c++/4.6/ostream|528|note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)|
/usr/include/c++/4.6/iomanip|78|note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Resetiosflags)|
/usr/include/c++/4.6/iomanip|108|note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setiosflags)|
/usr/include/c++/4.6/iomanip|142|note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, std::_Setbase)|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 15 warnings ===|
edytowany 2x, ostatnio: furious programming, 2013-06-15 22:07

Pozostało 580 znaków

2013-06-15 17:42
0

skoro używasz wcout to przeciążać musisz wostream:

wostream& operator<<(wostream& os,const BasicExcelCell& cell)

Wykonuję programy na zamówienie, pisać na Priv.
Asm/C/C++/Pascal/Delphi/Java/C#/PHP/JS oraz inne języki.

Pozostało 580 znaków

2013-06-16 16:43
0

Dzięki, naprowadziliście mnie :)
po prostu

cout << *cell << endl; 

działa
Co prawda wide string nie jest wyświetlany jak trzeba, ale będę próbował to jakoś ogarnąć :)

edytowany 1x, ostatnio: Mc_Hammer, 2013-06-16 16:45
powiedz jaki kompilator, jaki system i podaj przykład kodu, który "nie wyświetla jak trzeba" - Azarien 2013-06-16 20:16

Pozostało 580 znaków

Liczba odpowiedzi na stronę

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0