Karim
01-27-2005, 01:04 AM
/***** common.h *****/
void open_database(ofstream &out);
Everything works if I don't pass anything to the function otherwise the compiler screams with:
In file included from recordsub.cpp:4:
common.h:3: `ofstream' was not declared in this scope
common.h:3: `out' was not declared in this scope
common.h:3: variable or field `open_database' declared void
recordsub.cpp: In function `int main()':
recordsub.cpp:24: `open_database' cannot be used as a function
/***** common.cpp *****/
#include iostream
#include fstream
#include "common.h"
using namespace std;
void open_database(ofstream &out)
{
out.open ("submissions", ios::binary);
if (out.fail())
{
cout << "Error: The database did not open..." << endl;
}
return;
}
/***** recordsub.cpp *****/
#include cstdlib
#include fstream
#include iostream
#include "common.h"
#define MAX_NAME_LEN 50
using namespace std;
struct Record
{
char name[MAX_NAME_LEN + 1]; //citizen tax data
int sin;
double income;
streampos left; //links to left and right subtrees
streampos right;
};
int main()
{
ofstream out;
open_database(out);
out.close();
return 0;
}
I thought it might have been something wrong with my makefile but it works as long as I don't include any arguments in the header file. I figure it's something pretty simple but do you think I can see it?
void open_database(ofstream &out);
Everything works if I don't pass anything to the function otherwise the compiler screams with:
In file included from recordsub.cpp:4:
common.h:3: `ofstream' was not declared in this scope
common.h:3: `out' was not declared in this scope
common.h:3: variable or field `open_database' declared void
recordsub.cpp: In function `int main()':
recordsub.cpp:24: `open_database' cannot be used as a function
/***** common.cpp *****/
#include iostream
#include fstream
#include "common.h"
using namespace std;
void open_database(ofstream &out)
{
out.open ("submissions", ios::binary);
if (out.fail())
{
cout << "Error: The database did not open..." << endl;
}
return;
}
/***** recordsub.cpp *****/
#include cstdlib
#include fstream
#include iostream
#include "common.h"
#define MAX_NAME_LEN 50
using namespace std;
struct Record
{
char name[MAX_NAME_LEN + 1]; //citizen tax data
int sin;
double income;
streampos left; //links to left and right subtrees
streampos right;
};
int main()
{
ofstream out;
open_database(out);
out.close();
return 0;
}
I thought it might have been something wrong with my makefile but it works as long as I don't include any arguments in the header file. I figure it's something pretty simple but do you think I can see it?