error passing ifstream. why?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Giulio

    error passing ifstream. why?

    I've the following error in the sample code below.. I think it's caused from
    the passing of istream.
    what causes this problem?
    how can I solve it?

    thank you very much

    Giulio


    ---------------------------------------
    Compiler: Default compiler
    Building Makefile: "G:\Makefile.wi n"
    Executing make...
    make.exe -f "G:\Makefile.wi n" all
    g++.exe -c main.cpp -o
    ain.o -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/
    Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include"

    C:/Dev-Cpp/include/c++/bits/ios_base.h: In copy constructor
    `std::basic_ios <char, std::char_trait s<char> >::basic_ios(co nst
    std::basic_ios< char, std::char_trait s<char> >&)':
    C:/Dev-Cpp/include/c++/bits/ios_base.h:421: `std::ios_base: :ios_base(const
    std::ios_base&) ' is private
    main.cpp:12: within this context
    C:/Dev-Cpp/include/c++/streambuf: In copy constructor
    `std::basic_fil ebuf<char,
    std::char_trait s<char> >::basic_filebu f(const std::basic_file buf<char,
    std::char_trait s<char> >&)':
    C:/Dev-Cpp/include/c++/streambuf:486: `std::basic_str eambuf<_CharT,
    _Traits>::basic _streambuf(cons t std::basic_stre ambuf<_CharT, _Traits>&)
    [with _CharT = char, _Traits = std::char_trait s<char>]' is private
    main.cpp:12: within this context

    make.exe: *** [main.o] Error 1

    Execution terminated
    --------------------------------------

    the CODE
    ------------------------------------
    #include <fstream>
    #include <iostream>
    #include <stdlib.h>
    #include <string>
    using namespace std;
    int importFromCSV(i fstream is){
    return 5;
    }//end importFromCSV

    main (int argc, char *argv[]){
    ifstream is ("aaa");
    int q = importFromCSV(i s);
    cout << q;
    system ("pause");
    return 0;
    }
    -----------------------------


  • Victor Bazarov

    #2
    Re: error passing ifstream. why?

    "Giulio" <giulio.gL E V A@email.it> wrote...[color=blue]
    > I've the following error in the sample code below.. I think it's caused[/color]
    from[color=blue]
    > the passing of istream.
    > what causes this problem?[/color]

    std::ifstream doesn't have a usable copy c-tor.
    [color=blue]
    > how can I solve it?[/color]

    Never pass streams by value. Always use references.

    Victor


    Comment

    • Jon Bell

      #3
      Re: error passing ifstream. why?

      In article <EU2Ka.38798$Fr 5.835330@tornad o.fastwebnet.it >,
      Giulio <giulio.gL E V A@email.it> wrote:[color=blue]
      >I've the following error in the sample code below.. I think it's caused from
      >the passing of istream.[/color]

      Yes. You can't pass istreams by value, because you can't copy them. Pass
      them by reference instead.
      [color=blue]
      >int importFromCSV(i fstream is){[/color]

      Change that to

      int importFromCSV(i fstream& is){

      --
      Jon Bell <jtbellap8@pres by.edu> Presbyterian College
      Dept. of Physics and Computer Science Clinton, South Carolina USA

      Comment

      Working...