Chris Csernica

I'm trying to get at the Enumerator of the ValuesCollection of a Dictionary, but the trouble is that the compiler doesn't seem to know these classes exist. Declarations such as the following result in the compiler handing me a C2065 when I try to reference the variables.

Code Snippet
using namespace System;
using namespace System::Collections::Generic;

--snip--

Dictionary<TKey, TVal>::ValueCollection::Enumerator ^denum;
Dictionary<TKey, TVal>::ValueCollection ^dvc;


IntelliSense provides correct menus at each level, and at least for the declaration shows the correct Quick Info, but it doesn't see the Values property of the Dictionary at all, or any of its members. I thought perhaps this was a bug in IntelliSense, so I went ahead and tried compiling it anyway, but that was useless.

Is there some setting I might have hit sometime in the past and forgotten about that can cause this What am I missing

The workaround is pretty obvious, but it would be nice if this were working as I expect.

(Sorry for not posting a real code snippet, but my development machine isn't networked.)



Re: Visual C++ General Dictionary<TKey, TVal> subclasses invisible

Ramkrishna Pawar

Are those public types inside Dictionary class If not(in case of protected), you might try to derive a public class from it and use them there.






Re: Visual C++ General Dictionary<TKey, TVal> subclasses invisible

Chris Csernica

Ramkrishna Pawar wrote:

Are those public types inside Dictionary class If not(in case of protected), you might try to derive a public class from it and use them there.

The documentation says they're public. See http://msdn2.microsoft.com/en-us/library/x8bctb9c(vs.80).aspx et al.

I've seen a number of examples of this kind of thing, and there's never a suggestion that you might run into a problem of this nature.





Re: Visual C++ General Dictionary<TKey, TVal> subclasses invisible

Ramkrishna Pawar

MSDN says this was added in .NET framework 2.0, are you sure you are using 2.0 and above Which version of Visual Studio you have






Re: Visual C++ General Dictionary<TKey, TVal> subclasses invisible

Chris Csernica

YES, I'm using .NET 2.0, and I'm using VS 2005 Pro SP-1. I've pretty much eliminated all the glaringly obvious possible causes already.





Re: Visual C++ General Dictionary<TKey, TVal> subclasses invisible

Ramkrishna Pawar

I got it, you have a spelling mistake, it's not ValuesCollection, it's a ValueCollection.






Re: Visual C++ General Dictionary<TKey, TVal> subclasses invisible

Chris Csernica

As I pointed out in the OP, this isn't a real code snippet. My development machine isn't networked so I had to enter it by hand, and that was just a typo. My code had it spelled correctly. It ought to have been; it was handed to me by IntelliSense. That's one of the puzzling things here: Intellisense knows about the type but doesn't recognize any properties of that type, and the compiler doesn't seem to know about at all.





Re: Visual C++ General Dictionary<TKey, TVal> subclasses invisible

Holger Grund

If I understand correctly, you say you get an error at a line where you try to use the declared variables. If so, this has nothing to do with the type of the variables.

Are you sure the variables are still in scope at the point of use Preprocessing your source code can help you rule out odd things happening during this translation phase.

It would certainly help to see the exact error message along with source code for the flagged line.

BTW: Concrete implementations of IEnumerator are typically value types. Not sure, whether's true for your example, too. But if so, you might want to leave out the ^ for denum.

-hg





Re: Visual C++ General Dictionary<TKey, TVal> subclasses invisible

Chris Csernica

It's the very next line, so it would be very odd if it had fallen out of scope at that point.

This is just the generic Dictionary class, it should be the default IEnumerator implementation for its ValueCollection. Now that I've taken a closer look at the official docs, I see it's indeed a value type.

(That means I can positively NOT recommend Pro Visual C++/CLI and the .NET 2.0 Platform by Stephen Fraser, to which I resorted for lack of examples in the official docs. Not only is it an annoying read with his conversational interjections and typographical errors, but now I know his examples can be wrong. His discussion of the ValueCollection and KeyCollection classes on pp. 274-277 clearly shows Dictionary<>::ValueCollection::Enumerator as a handle.)

Unfortunately, a correct declaration doesn't fix the problem. The compiler still doesn't see the variable as having been declared, and still doesn't appear to see the Value method of a Dictionary.

I'll post the actual code and compiler errors in a few minutes.

Hah. A few minutes, I says. Sorry if this is a bit messy; I didn't have much luck screwing around with it to make it look good.

Code Snippet

7 using namespace System;
8 using namespace System::Collections::Generic;

...

12 public ref struct dwell_info {

...

19 DateTime start_time;
20 DateTime end_time;
21 dwell_status_values status;
22 };
23
24 public ref class dwells {
25
26 static Dictionary<String^, Generic::Queue<dwell_info^>^> ^dwell_list;

...

89 static DateTime cur_dwell_start() {

90 Dictionary<String^, Generic::Queue<dwell_info>^>::ValueCollection::Enumerator stpr
91 = dwell_list->Values;
92 if (!sptr.MoveNext()) {
93 return DateTime::MinValue;
94 }
95 return sptr.Current->Peek().start_time;


};



Compile-time output:

1>------ Build started: Project: dutp_utilities, Configuration: Debug Win32 ------
1>Compiling...
1>Stdafx.cpp
1>Compiling...
1>dutp_utilities.cpp
1>c:\documents and settings\csernica\my documents\visual studio 2005\projects\dutp\dutp_utilities\dutp_dwells.h(92) : error C2065: 'sptr' : undeclared identifier
1>c:\documents and settings\csernica\my documents\visual studio 2005\projects\dutp\dutp_utilities\dutp_dwells.h(92) : error C2228: left of '.MoveNext' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\csernica\my documents\visual studio 2005\projects\dutp\dutp_utilities\dutp_dwells.h(95) : error C2228: left of '.Current' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\csernica\my documents\visual studio 2005\projects\dutp\dutp_utilities\dutp_dwells.h(95) : error C2227: left of '->Peek' must point to class/struct/union/generic type
1>c:\documents and settings\csernica\my documents\visual studio 2005\projects\dutp\dutp_utilities\dutp_dwells.h(95) : error C2228: left of '.start_time' must have class/struct/union
1>asmcs_report_reader.cpp
1>c:\documents and settings\csernica\my documents\visual studio 2005\projects\dutp\dutp_utilities\dutp_dwells.h(92) : error C2065: 'sptr' : undeclared identifier
1>c:\documents and settings\csernica\my documents\visual studio 2005\projects\dutp\dutp_utilities\dutp_dwells.h(92) : error C2228: left of '.MoveNext' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\csernica\my documents\visual studio 2005\projects\dutp\dutp_utilities\dutp_dwells.h(95) : error C2228: left of '.Current' must have class/struct/union
1> type is ''unknown-type''
1>c:\documents and settings\csernica\my documents\visual studio 2005\projects\dutp\dutp_utilities\dutp_dwells.h(95) : error C2227: left of '->Peek' must point to class/struct/union/generic type
1>c:\documents and settings\csernica\my documents\visual studio 2005\projects\dutp\dutp_utilities\dutp_dwells.h(95) : error C2228: left of '.start_time' must have class/struct/union
1>Build log was saved at "
file://c:\Documents and Settings\csernica\My Documents\Visual Studio 2005\Projects\dutp\dutp_utilities\Debug\BuildLog.htm"
1>dutp_utilities - 10 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========






Re: Visual C++ General Dictionary<TKey, TVal> subclasses invisible

Holger Grund

Call me an idiot, but doesn't make the message perfect sense

The compiler complains about sptr (_not_ stpr) and you have declared stpr (and _not_ sptr).

Also >> is a single token and the C++ standard doesn't allow them to close to template-ids (rather it's interpreted as right shift). However, the standard committee has indicated it will be supported in a future standard and VC++ already implements that. So it should be just fine for generics, too.

Other than this, it's probably Current.Value-> instead of Current->. But then I don't even have an SDK installed on the box I'm typing this on.

-hg





Re: Visual C++ General Dictionary<TKey, TVal> subclasses invisible

Chris Csernica

A typo. How annoying.

There were actually two, although only one of them accurately reflected what was in the code. I made the mistake of monkeying with it when I was getting the lines to post, and tried to update it here by hand. Dictionary<String^, Generic::Queue<dwell_info^>> is a typo; it should have been Dictionary<String^, Generic::Queue<dwell_info>^>.

I would expect Current to be of the value type there, which is a handle to a Queue, so the -> should be correct.

Thank you! I suspect I've not been getting enough sleep, to miss stupid errors like that. If IntelliSense knew about the subclass, I'd have spotted it right away. That bit still doesn't work, typos or no, but it does compile.

-- C