简体   繁体   中英

c++ declaring a function with ostream in class header

I am having problems declaring a class function from the header file, am not sure how it should be formatted in the header. The purpose of this is to save class object data into a file, to be able to read back in later.

employee.h

void writedata(ofstream);

employee.cpp

void Employee::writedata(ofstream& employeewrite)
{
}

Employeewrite is the ostream object I declared in main

main.cpp

ofstream employeewrite("c:\\test\test.txt");

Thanks for any help.

You're declaring writedata to take a ofstream in your header, but defining it to take an ofstream& (a reference to an ofstream ) in the source file. Make them match up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM