-
Small errors
I have just added two variables to an object, which was already working, to a class of mine.. author and isbn. Here is a section of the code.
Code:
#include<iostream>
#include<fstream>
#include<stdlib>
#include<time>
#include<string>
#include<ctype>
#define KBYTE 1024
using namespace std;
class bookobject
{
protected: //new fields here which means
char name[KBYTE]; //changeing the edit function
char author[KBYTE]; //and books2file -
char isbn[KBYTE]; //so new constructor << =
int number; //and methods to access and change fields
//keep getName() setName() getNumber() setNumber()
private:
public:
bookobject(void)
{
strcpy(name, "");
strcpy(author, "");
strcpy(isbn, "");
number = -1;
}
The errors are caused by the following lines
char author[KBYTE];
char isbn[KBYTE];
I get these errors for both lines
1."Cannot convert 'std::basic_string<char,std::string_char_traits<ch ar>,std::allocator<char>>' to 'char *'
2."Type mismatch in parameter '_dest' in call to 'strcpy(char *, const char *)'
Hope that's the relevent bit, didn't want to post the whole lot. Thanks! (Full code attached if needed!)
-
Your headers are incorrect. They should be like so.
Code:
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<cstring>
#include<cctype>
#include<string>
The error you were asking about is concerning two names clashing in the constructor. If the parameter names match member names, you must either change the parameter names, or prefix the member names with "this->". Here is the corrected constructor in question.
Code:
bookobject(string nam, string author, string isbn, int num)
{
strcpy(name, nam.c_str());
strcpy(this->author, nam.c_str());
strcpy(this->isbn, nam.c_str());
number = num;
}