Classes and objects with strings

hey guys, Im working on a small text based RPG, and im creating a class called obj
to create all my swords and staffs and things, like such


[code/]

class obj
{
char name[];
int weight;
void attack();
void magic();
};

[/code]


my only problem is when i try to assign a name to my object like


obj sword;
sword.name = "Sword";


i keep getting a compiler error saying incompatable types in assignment of
const char [6] to char[0]

is there something special i have to do to assign a string to the class?


use a string, not a char array:

1
2
3
4
5
6
7
8
9
#include <string>  // <-

class obj
{
  std::string name;  // <-
  int weight;

  //...
};
Topic archived. No new replies allowed.