error passing ifstream. why?

G

Giulio

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.win"
Executing make...
make.exe -f "G:\Makefile.win" 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_traits<char> >::basic_ios(const
std::basic_ios<char, std::char_traits<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_filebuf<char,
std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char,
std::char_traits<char> >&)':
C:/Dev-Cpp/include/c++/streambuf:486: `std::basic_streambuf<_CharT,
_Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&)
[with _CharT = char, _Traits = std::char_traits<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(ifstream is){
return 5;
}//end importFromCSV

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

Victor Bazarov

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

std::ifstream doesn't have a usable copy c-tor.
how can I solve it?

Never pass streams by value. Always use references.

Victor
 
J

Jon Bell

I've the following error in the sample code below.. I think it's caused from
the passing of istream.

Yes. You can't pass istreams by value, because you can't copy them. Pass
them by reference instead.
int importFromCSV(ifstream is){

Change that to

int importFromCSV(ifstream& is){
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top