How to see type of a C++ variable?
Asked Answered
M

1

11

Suppose I have the following C++ code in Xcode 4.4.1.

int Func();

...

void Test()
{
    auto Variable = Func();

    ...

    DoSomething(Variable);
}

Suppose I want to find out the type of Variable in the 2nd last line. How can I do it in Xcode?

IIRC, in Visual Studio you put the mouse cursor over the variable and a tooltip appears. This doesn't happen in Xcode.

I know these 3 methods, but I want to know if there's something better I'm not aware of.

  1. If you hold alt and click Variable, it will say "defined in SomeFile.h".

  2. If you hold cmd and click Variable, it will take you to the line where Variable is defined. But then you have to find out the return type of Func() which involves more steps. I'm looking for the fastest way to do this.

  3. If you put your cursor at the end of Variable, and press Ctrl+Space it will show auto-complete with the type of Variable listed in there. This works, but it seems awfully indirect (e.g. if you put the cursor elsewhere, you might get a lot of entries in auto-complete list, forcing you to search for Variable). Is there a more direct way to do this?

How can I do find out the type of Variable in the 2nd last line in Xcode?

Miniskirt answered 19/8, 2012 at 18:8 Comment(0)
L
0

You can set a breakpoint at the variable for which you want the type, then run the code. Make sure you have the debugger tool open, Xcode will show you something like "Variable = (int) 0" or "Variable = (std::__1::string) 'variableIsString'."

Lao answered 3/2, 2015 at 23:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.