cannot convert 'struct name' to ‘class name' in initialization

Dear all,

I have a struct and a class :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
struct book{
    string name;
	string author;
	string publisher;
	string trasnlator;
	bool translation;
	int	delayDays;
	int delayPay;
	bool stock;
	struct client__{
		string firstName;
		string lastName;
		int memberNumber;
	}client_;
};

and my class is :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class WriteFile {
	public:
		WriteFile();
		WriteFile(client *clientPtr, book bookPtr);
		WriteFile(const client& clientPtr);
		WriteFile(const book& bookPtr);

		void writeToFile(FILE *fd,const book&  ptr);

	private:

		//void *filePtr;
		size_t clientDataSize;
		size_t bookDataSize;
		int errorNumber ;
	protected:

};

my implementation of constructror is :
1
2
3
4
5
WriteFile::WriteFile(const book&  bookPtr) {

	bookDataSize = sizeof (bookPtr);
	errorNumber = 0;
}

And implementation of writeToFile method is:
1
2
3
4
5
6
7
8
9
10
11
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


How do i solve it????

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.
I wrote a static function that initializes my struct but you know when initialize a struct must use the following format:
1
2
3
4
struct mystruct{
	int number;
	char alpha;
}ex = {23 , 'a'};

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
I said nothing of the sort; I pointed out your mistake and nothing more.
Topic archived. No new replies allowed.