Re: How to implement IEnumerator<T> in C++/CLI
- From: "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP@xxxxxxxxxxxxx>
- Date: Tue, 28 Feb 2006 07:01:24 -0600
Have you tried something like:
template<typename T>
ref class A : Generic::IEnumerator<T^>
{
private:
property System::Object^ CurrentObject
{
virtual Object^ get() sealed = IEnumerator::Current::get;
}
~A();
public:
property T^ Current
{
virtual T^ get();
}
virtual bool MoveNext(void);
virtual void Reset(void);
};
Although I would probably define it as:
template<typename T>
ref class A : Generic::IEnumerator<T>
{
private:
property System::Object^ CurrentObject
{
virtual Object^ get() sealed = IEnumerator::Current::get;
}
~A();
public:
property T Current
{
virtual T get();
}
virtual bool MoveNext(void);
virtual void Reset(void);
};
Allowing it to be used with either value or reference types.
A<String^> stringEnumerator;
A<Object^> objectEnumerator;
A<int> intEnumerator;
A<double> doubleEnumerator;
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"midnight madness" <midnight madness@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:B5F45301-8119-40DB-A0C6-1F72EFF6D278@xxxxxxxxxxxxxxxx
|I tried but failed to implement a template class that support
IEnumerator<T>
| interface using C++/CLI in VS 2005 Professional version. I could not
figure
| out the proper syntax to implement the property "Current". The challange
is
| that I need to implement two versions of the property: one of type
| System::Object as required by Collections::IEnumerator, the other of type
T^
| as required by Collections::Generic::IEnumerator<T>
|
| template<typename T>
| class A : IEnumerator<T^>
| {
| property System.Object^ Current {...}
|
| property T^ Current {...}
| };
|
| the article "Explicit Override of an Interface Member" in MSDN did not
help
| much. Any helps are greatly appreciated.
.
- Prev by Date: Re: Memeory 3G problems ?
- Next by Date: Re: Change project type in VC6
- Previous by thread: String was not recognized as a valid DateTime
- Next by thread: Get Device Notification Event in Windows Nt Services
- Index(es):