quick watch of an overloaded operator

V

vladimir

All,

I have seemingly quite known problem, namely I need to watch overloaded
[] in quick watch(by own vector) but I can not. It says overloaded
operator is not found. And that is claimed normal here (at least once).

But I have a project where at least for local class variables [] can be
watched. I see absolutely no difference in settings/options, and the
class is just copied from old project. Ans it is template class (if it
does matter).

template <class T>
class CVector
{

public:

//! Number of elements of the vector.
int m_nLength;
//! Pointer to elements of the vector
T* p;

........

//! Get ith element of a vector. use as vector
T& operator[] (int i) const
{
return p;
}

..............

}

making this inline operator (if it indeed become one) does not help.

Not very important but still would be better to find a way to watch...
Has somebody any idea?

And yes, things should be private, I know...
 
V

Victor Bazarov

vladimir said:
I have seemingly quite known problem, namely I need to watch overloaded
[] in quick watch(by own vector) but I can not. It says overloaded
operator is not found. And that is claimed normal here (at least once).

But I have a project where at least for local class variables [] can be
watched. I see absolutely no difference in settings/options, and the
class is just copied from old project. Ans it is template class (if it
does matter).

template <class T>
class CVector
{

public:

//! Number of elements of the vector.
int m_nLength;
//! Pointer to elements of the vector
T* p;

.......

//! Get ith element of a vector. use as vector
T& operator[] (int i) const


Bad idea. You're returning a non-const reference to something that is
stored in an object that can be 'const'. If it's a const vector, why
would you allow changing its contents? I know, I know, syntactically,
only 'p' and 'm_nLength' are const, not what 'p' points to, but still.
{
return p;
}

.............


What's here? Could it be you also provided

operator T*() { return p; }

??? You shouldn't, you know.
}

making this inline operator (if it indeed become one) does not help.

Not very important but still would be better to find a way to watch...

You keep using the verb "watch" here. Why? How is it relevant?
Has somebody any idea?

And yes, things should be private, I know...

It doesn't matter, most likely. What matters, though, is FAQ 5.8.

V
 
V

vladimir

Old code isn`t mine actualy. I am doing it now according to all rules,
but I can not answer other's question "why it is not possible to use MS
Visual C++ Quick Watch function (basically, highlite a[1] inclusion and
see value) while debugging whereas it was possible with old class?" In
new project old class does not do it either, and all sources I could
reach says it is normal not to see it in quick watch. But I see it!!!
How to reach this functionality with my new improved class is my main
and only concern.
 
V

vladimir

Old code isn`t mine actualy. I am doing it now according to all rules,
but I can not answer other's question "why it is not possible to use MS
Visual C++ Quick Watch function (basically, highlite a[1] inclusion and
see value) while debugging whereas it was possible with old class?" In
new project old class does not do it either, and all sources I could
reach says it is normal not to see it in quick watch. But I see it!!!
How to reach this functionality with my new improved class is my main
and only concern.
 
V

Victor Bazarov

vladimir said:
Old code isn`t mine actualy. I am doing it now according to all rules,
but I can not answer other's question "why it is not possible to use MS
Visual C++ Quick Watch function (basically, highlite a[1] inclusion and
see value) while debugging whereas it was possible with old class?"

Since you didn't post the "old class", I have no idea why there is any
difference between the two. However, I can probably answer your question
partially.

First of all, "Visual C++ Quick Watch" is off-topic here. You should try
'microsoft.public.vc.ide_general' newsgroup for questions about Microsoft
Visual C++ IDE.

Second of all, when "watching" something in a debugger requires a function
call (like with your overloading operator[]), the debugger most likely
will *not* be able to display anything because the *debugger* has no idea
how to call a function. In that case you should examine the object itself
(in your case 'a') and see the 'p' member and index that array manually in
the debugger.

Good luck, and next time post a C++ _language_ question. Any *tools* like
debuggers, compilers, linkers, editors, etc., are most likely off-topic
here and should be discussed in their own respective newsgroups.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top