0

In using a struct item:

struct item
{
    item();
    ~item();
    char * name;
    char * effect1;
    char * effect2;
    char * effect3;
    char * effect4;
    int count;
};

with the constructor:

item::item()
{
    name = NULL;
    effect1 = NULL;
    effect2 = NULL;
    effect3 = NULL;
    effect4 = NULL;
    count = 0;
}

Hovering over name shows:

char* name() const

while hovering over any of the effects shows:

char* effectx

I am wondering why this is happening as I believe the difference is causing me problems in other areas of my program. Thank you.

Flexo1515
  • 1,007
  • 1
  • 10
  • 27
  • 5
    You say you that "*hover over name*". What program are you using when you hover over name? A code editor? An IDE? Which one? – Robᵩ May 21 '12 at 20:28
  • 1
    Sounds just like a quirk in the system. Do you have any function called `name()`? – K-ballo May 21 '12 at 20:28
  • @hmjd no item has no member functions other than item() and ~item. – Flexo1515 May 21 '12 at 20:29
  • 1
    `const char*` makes sense if all names are directly given as string literals (`"somecaption"`), otherwise you should use the idiomatic C++ alternative instead, which is neither `char*` nor `const char*` but `std::string`. – leftaroundabout May 21 '12 at 20:31
  • @Robᵩ I am using DevC++ at the moment, the only reason I believe there is something truly different about them is because later on when I run another part of the program using the same code for both the name and the effects, it works fine for the name but not for the effects – Flexo1515 May 21 '12 at 20:31
  • @leftaroundabout it's for a class, so no strings permitted. The names and effects are brought in from a text file character by character and then passed into an item, all in the same fashion, yet the result is one comes out as const and one char* – Flexo1515 May 21 '12 at 20:32
  • 2
    Aside: "*item has no member functions other than item() and ~item.*". You have violated the [Rule of Three](http://stackoverflow.com/questions/4172722/what-is-the-rule-of-three). – Robᵩ May 21 '12 at 20:36
  • 1
    Sounds to me like your IDE is buggy. It's probably conflating your member `name` with the member function from another class which has a member function declared as `char* name() const`. – Adam Rosenfield May 21 '12 at 20:40

1 Answers1

1

I don't think the declaration you have presented is quite the same as the code the IDE is seeing. One good way to work on the problem is to duplicate the code into a separate working file (in a separate project) and move all the code (both declaration and the example code showing the problem) into the same file. Then remove unrelated parts of the code so that you slowly move towards the smallest, most condensed, example that still shows your problem.

Then post that code as an update to your question.

Meanwhile, you're not defining your constructor quite correctly. Well it's correct, but not the best style. Don't initialise members in the body of the constructor, initialise them like this:

item::item()  : 
 name(NULL), effect1(NULL), effect2(NULL), effect3(NULL), effect4(NULL), count(0)
{
  /* nothing in the body. */
}
James Youngman
  • 3,623
  • 2
  • 19
  • 21