Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   error passing ifstream. why? (http://www.velocityreviews.com/forums/t267675-error-passing-ifstream-why.html)

Giulio 06-24-2003 08:54 PM

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.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;
}
-----------------------------



Victor Bazarov 06-24-2003 09:15 PM

Re: error passing ifstream. why?
 
"Giulio" <giulio.gL E V A@email.it> wrote...
> 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



Jon Bell 06-24-2003 09:19 PM

Re: error passing ifstream. why?
 
In article <EU2Ka.38798$Fr5.835330@tornado.fastwebnet.it>,
Giulio <giulio.gL E V A@email.it> wrote:
>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){

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


All times are GMT. The time now is 06:53 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.