469,909 Members | 1,799 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

How to implement IEnumerator<T> in C++/CLI

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.
Feb 26 '06 #1
1 3415
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 ma*****@discussions.microsoft.com> wrote in
message news:B5**********************************@microsof t.com...
|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.
Feb 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by nicolas.rolland | last post: by
15 posts views Thread by Gustaf | last post: by
7 posts views Thread by Andrew Robinson | last post: by
4 posts views Thread by Anastasios Hatzis | last post: by
3 posts views Thread by ajay2552 | last post: by
2 posts views Thread by Henri.Chinasque | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.