David912 David912 - 5 months ago 49
C++ Question

How to access a member of a pointer to object

I need some clarification about this issue. I have a class called con.

class con
int readIndex;

in con.cpp:

readIndex = 0;

in main:

con = new con();

now readIndex is not 0 as I wanted. Watch window shows that the value is
0xcdcdcdcd {???}
and the type is now
and not
which means that a variable will become a pointer if it's class object is created using
? I then tried to change the code to
*readIndex = 0;
but I got a write access violation. So how should I set the value of readIndex to 0 after all?

Answer Source

It should definitely initialize readIndex to 0. Just put one print statement and check whether your constructor called properly or not.

Also try with

con::con():readIndex(0) { }

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download