#include <fstream>
using namespace std;

void a(ifstream b){}
void main()
{
    ifstream b("c.txt");
    a(b);                      // error caused when function a() is used
}

Why is this producing an error?

Thank you,
Thumb2

Why do you have an extra set of parentheses on the end of your function prototype? Get rid of those and put a semicolon at the end.

Also, you probably want to pass in ifstream by reference:
void a(ifstream & b) in your prototype, nothing extra required in the function call itself.

Comments
Straight to the solution

>Why is this producing an error?
Stream objects aren't copyable at the object level. As jonsca said, you need to pass a reference to the ifstream.

Also, I forgot to say in my first post that the ampersand should be included in your function definition as well.

Edited 6 Years Ago by jonsca: n/a

Why do you have an extra set of parentheses on the end of your function prototype? Get rid of those and put a semicolon at the end.

Is it preferred that I use prototypes, even in simplified programs?

I was trying to make it easier to look at, for example:

//headers

void a(ifstream &b){}   // do nothing
void main()
{
    //code
}

versus the prototyped version:

//headers

void a(ifstream &);
void main()
{
    //code
}
void a(ifstream &b){}  // do nothing

//*************************
Passing by reference did solve it; thank you very much for the quick reply!

Edited 6 Years Ago by Thumb2: Self-conscious about the error still present in the examples. I'm weak.

For a small scale project (i.e. 1 file) you can certainly get away with popping your function definition in its entirety before main(). When dealing with library functions, prototypes are essential because you don't have direct access to the original code for the most part.

This question has already been answered. Start a new discussion instead.