Thread: Small errors

  1. #1
    Registered User
    Join Date
    Mar 2004

    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.

    #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()
    		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!)

  2. #2
    Registered User
    Join Date
    May 2004
    Your headers are incorrect. They should be like so.
    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.
    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;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to split long programe in small files
    By umeshjaviya in forum C Programming
    Replies: 11
    Last Post: 04-15-2008, 02:45 AM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  3. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  4. executing errors
    By s0ul2squeeze in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2002, 01:43 PM