0

I'm a begginer in C++ and trying to create a new instance of a class

foo* a= new foo(1);
*(a).kCreateThread();

and I get the following error

error C2228: left of '.kCreateThread' must have class/struct/union

What is wrong?

ᴘᴀɴᴀʏɪᴏᴛɪs
  • 7,169
  • 9
  • 50
  • 81
  • 3
    `(*a).kCreateThread();`. Your syntax tries to call a.kCreateThread() and dereference the return value of it, while mine first dereferences the pointer a and then tries to call kCreateThread with it. This is because * has lower precedence then . – Creris Oct 18 '14 at 10:32
  • 1
    [This operator precedence table might help.](http://en.cppreference.com/w/cpp/language/operator_precedence) – Some programmer dude Oct 18 '14 at 10:38

2 Answers2

3

What you wrote is equivalent to

*((a).kCreateThread());

You should use

a->kCreateThread();

or

(*a).kCreateThread();

These last two are equivalent.

Alberto Santini
  • 6,425
  • 1
  • 26
  • 37
1

Do it like this: a->kCreateThread();

Mosa
  • 373
  • 1
  • 14