-4

I cannot get the reason of the error. Please, help.

class Dog
{
private:
    char name[25];
    int gender;
    int age;
    int size;
    bool healthy;

public:
    char* getName() { return name; }
    int   getGender() { return gender; }
    int   getAge() { return age; }
    int   getSize() { return size; }
    bool  isHealthy() { return healthy; }
    void  setHealthy(bool dhealthy) { healthy = dhealthy; }
    void  setName(char* dname) { name = dname; } // name ---> Expression must be a modifiable value
};
NoWar
  • 36,338
  • 80
  • 323
  • 498
  • You cannot (re-)initialize an array definition like that. Use `std::copy()` or something like that. – πάντα ῥεῖ Jul 01 '16 at 19:07
  • 1
    you could use `std::string` – 463035818_is_not_an_ai Jul 01 '16 at 19:07
  • You're writing a c program in c++, and [c++ is not c](http://www.lb-stuff.com/cc). I recommend you spend some time with some proper c++ tutorials. – Xirema Jul 01 '16 at 19:08
  • @Xirema Yeah... That is what I found here https://en.wikiversity.org/wiki/C%2B%2B/Classes_and_Inheritance – NoWar Jul 01 '16 at 19:10
  • 3
    99,99% of all online tutorials are crap. Once you can spot the 0,01% you dont need them anymore. If you really want to learn C++ you should get a [book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – 463035818_is_not_an_ai Jul 01 '16 at 19:12
  • 1
    @Dimi If you check the history for that page, you'll see that the `Dog` example dates from nearly a decade ago. C++, and the "Best Practices" for using the language have changed significantly since then, and that example doesn't represent a reliable tutorial anymore. – Xirema Jul 01 '16 at 19:16

1 Answers1

2

You cannot assign a pointer to an array. If you want to copy a string, use strcpy.

Or, since this is tagged C++, consider using an actual string type.

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574