void WriteFile::writeToFile(FILE *fd,const book& ptr ){
if (!feof(fd))
fseek(fd,0,SEEK_END); // check if not end of file seek to end of file.
// if (fwrite(ptr,sizeof(ptr),sizeof(ptr),fd) != 0)
errorNumber = fileno(fd);
// return errorNumber;
}
And my main program is :
1 2 3 4
book *bookPtr ;
WriteFile *writePtr(bookPtr);
writePtr->writeToFile(bookFilePtr,bookPtr);
So i get the following err after compile:
1 2 3 4 5 6 7 8
g++ -I. -O2 -g -Wall -fmessage-length=0 -c -o library.o library.cpp
library.cpp: In function ‘int main()’:
library.cpp:73:29: error: cannot convert ‘book*’ to ‘WriteFile*’ in initialization
library.cpp:75:43: error: no matching function for call to ‘WriteFile::writeToFile(std::fstream&, book*&)’
library.cpp:75:43: note: candidate is:
writefile.h:22:8: note: void WriteFile::writeToFile(FILE*, const book&)
writefile.h:22:8: note: no known conversion for argument 2 from ‘book*’ to ‘const book&’
make: *** [library.o] Error 1
WriteFile *writePtr(bookPtr);
This creates a pointer to a WriteFile and tries to assign it to the value of bookPtr, which points to nothing of type book.
And i have a static pointer in my class class myclass {static mystruct * myptr;}
And i wrote the following code in my implementation file : book *myclass::myptr = ex;
But i get the following error in cpp file: error: cannot convert ‘mystruct’ to ‘mystruct*’ in initialization
I solved second error.i defined it in the global.h and global.cpp within extern 'c' { } block.
LB, you told i must initialize my struct and then use it but i initialized it and but get the same erro: error: cannot convert ‘book*’ to ‘WriteFile*’ in initialization