When I debug the small piece of code below, visual studio debugger doesn't show the value of the struct
I pushed into the deque
, it just show all fields name = ???. All the other var are correctly watched!
does someone already have the same issue ?
typedef struct ToTestDrift{
int num;
uint64_t pts;
ToTestDrift(int n, uint64_t ts): num(n), pts(ts) {}
ToTestDrift(const ToTestDrift& ro):num(ro.num), pts(ro.pts) {}
} drift_t;
ifstream input("test.txt");
std::deque<drift_t> drift;
while(!input.eof())
{
int framenum; uint64_t pts;
input >> pts >> framenum;
push_back(drift)(framenum, pts);
}
NOTE: I use a boost range adaptor to push_back, but it's the same with drift.push_back
!
And if I extract a value like in the following code, in taht case a watch
on t
is OK...
BOOST_FOREACH(frame_info_t t, tocheck)
{
if(t.pts != 0)
{
fprintf(stdout, "%d \t %0.2f \t %0.e2f \t %d \t %d \n", t.framenum, t.pts, t.drift, t.period, t.type);
}
}//*/
I finally found the reason behind that weird issue.
The code I provided is not C++98 compliant and shouldn't compile (in fact it doesn't compile with GCC). The reason is that we can't use a local to a function, struct/class definition, with a template (container or other...), read that post for more info.
And in fact in the visual compiler accept that code, as there is no ID for the struct/class and for their fields, the debugger is "a bit lost"....
I moved the struct/class definition out-side my function, and now the compiler create an ID for the struct/class and the debugger works as usual.
So instead of
int function()
{
typedef struct ToTestDrift{
int num;
uint64_t pts;
ToTestDrift(int n, uint64_t ts): num(n), pts(ts) {}
ToTestDrift(const ToTestDrift& ro):num(ro.num), pts(ro.pts) {}
} drift_t;
ifstream input("test.txt");
std::deque<drift_t> drift;
while(!input.eof())
{
int framenum; uint64_t pts;
input >> pts >> framenum;
push_back(drift)(framenum, pts);
}
}
Write
typedef struct ToTestDrift{
int num;
uint64_t pts;
ToTestDrift(int n, uint64_t ts): num(n), pts(ts) {}
ToTestDrift(const ToTestDrift& ro):num(ro.num), pts(ro.pts) {}
} drift_t;
int function()
{
ifstream input("test.txt");
std::deque<drift_t> drift;
while(!input.eof())
{
int framenum; uint64_t pts;
input >> pts >> framenum;
push_back(drift)(framenum, pts);
}
}
NOTE that the first version of the code is compliant with the new C++11, all new compiler relaxed that limitation, so local function definition of a struct/class should work fine with visual studio 2013.