Interesting little problem

I have a simple console app using C++/CLI:

#include "stdafx.h"

using namespace System;

enum Values
{
ONE = 1,
TWO = 2,
THREE = 3
};

struct Params
{
public: int n;
public: Values v;

};

public ref class Foo
{
public: Params* p;

public: Foo()
{
p = new Params;

p->n = 42;
p->v = ONE;
}

public: ~Foo()
{
delete p;
}
};

int main(array<System::String ^> ^args)
{
Foo^ f = gcnew Foo();

return 0;
}

The problem I'm having is that I set a breakpoint at:
p->v = ONE;
in the Foo constructor.

It remains undefined.

I can't seem to assign p->v when it's a native enum. Assigning p->n is no problem.

Any ideas



Answer this question

Interesting little problem

  • szerencsi

    I'm also agreeing with Nishant on this one.  You should open a bug on this so it can get fixed.

     plus the forum editor need to get fixed too :)


  • Novicestd

    Hi,

    may be you should access the enums via v:

    p->v = v.ONE;

    If this does not work try:

    p->v = &v.ONE;

    hope this helps

    Regards

  • brucef

    It's just like Nishant Sivakumar mentioned, the VS debugger doesn't resolve native type variables very well...
    You can check that your code is doing what's supposed to do by debugging in "old ways":
    System::Diagnostics::Debug::WriteLine((int)p->v);


  • adechiaro

    Yes,

    I just did this inside the Foo constructor:

    p->v = TWO;
    p->n = (int)p->v; // shows 2 in the debugger

  • Robs Pierre

    Hi,

    thats interesting. So this actually means that everytime i use a pointer of a struct s on an enum i may run into an unwanted breakpoint.


  • ssli2005

    It's just an issue with the debugger - which can't seem to figure out native enums. Your code is otherwise fine and works as expected too.

    break_r wrote:
    I have a simple console app using C++/CLI:

    #include "stdafx.h"

    using namespace System;

    enum Values
    {
    ONE = 1,
    TWO = 2,
    THREE = 3
    };

    struct Params
    {
    public: int n;
    public: Values v;

    };

    public ref class Foo
    {
    public: Params* p;

    public: Foo()
    {
    p = new Params;

    p->n = 42;
    p->v = ONE;
    }

    public: ~Foo()
    {
    delete p;
    }
    };

    int main(array<System::String ^> ^args)
    {
    Foo^ f = gcnew Foo();

    return 0;
    }

    The problem I'm having is that I set a breakpoint at:
    p->v = ONE;
    in the Foo constructor.

    It remains undefined.

    I can't seem to assign p->v when it's a native enum. Assigning p->n is no problem.

    Any ideas



  • Interesting little problem