473,378 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Casting and templates...

Hi there

The following code doesn't complie:
__________________________________________________ ______
public interface ITree
{
ITree GetFather ();
List<ITreeGetChildren();
}
public class A : ITree
{
protected A m_father;
protected List<Am_ListChildren;

public ITree GetFather() { return m_father; }
public List<ITreeGetChildren() { return m_ListChildren; }
}
__________________________________________________ ______

since "Error 2 Cannot implicitly convert type
'System.Collections.Generic.List<XMLTreeview.A>' to
'System.Collections.Generic.List<XMLTreeview.ITree >'

However A inherits from ITree, so the cast should be working no...
Is there any workaround ?

Oriane

Oct 31 '07 #1
2 1132
Hi Oriane,

Classes use polymorphism till they are not generic types :)
So, you can use something like this "new List<ITree>(m_ListChildren.ToArray());"
to convert the values.

Regards, Alex
[TechBlog] http://devkids.blogspot.com
O......
Opublic class A : ITree
O{
Oprotected A m_father;
Oprotected List<Am_ListChildren;
Opublic ITree GetFather() { return m_father; }
Opublic List<ITreeGetChildren() { return m_ListChildren; }
O} .....
OHowever A inherits from ITree, so the cast should be working no... Is
Othere any workaround ?
Oct 31 '07 #2

"Alex Meleta" <am*****@gmail.coma ecrit dans le message de
news:15**************************@msnews.microsoft .com...
Hi Oriane,

Classes use polymorphism till they are not generic types :)
Good point :-(
So, you can use something like this "new
List<ITree>(m_ListChildren.ToArray());" to convert the values.
Set and match !!

Thanks !!

Nov 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jacob Jensen | last post by:
This question has probably been asked a million time, but here it comes again. I want to learn the difference between the three type cast operators: static_cast, reinterpret_cast, dynamic_cast. A...
3
by: Brian Byrne | last post by:
I've recently developed a minor interest in Expression Templates and, in attempt to further my understanding of template metaprogramming, have been trying to create my own implementation. It seems...
35
by: ytrama | last post by:
Hi, I have read in one of old posting that don't cast of pointer which is returned by the malloc. I would like to know the reason. Thanks in advance, YTR
4
by: ITnerd | last post by:
In the interest of code re-use, I would like to place some code in a utility class to be used by other classes. The problem is that this code requires the following snippet: for(i=0; i <...
7
by: S. Lorétan | last post by:
Hi guys, Sorry for this stupid question, but I don't know why it isn't working. Here is my (example) code: namespace Test { class A { public string Label1; }
5
by: brekehan | last post by:
I've always been a little sketchy on the differences between static, dynamic, and reinterpret casting. I am looking to clean up the following block by using C++ casting instead of the C style...
11
by: Frederic Rentsch | last post by:
Hi all, If I derive a class from another one because I need a few extra features, is there a way to promote the base class to the derived one without having to make copies of all attributes? ...
3
by: Vincent Finn | last post by:
Hi, I am trying to write a generic function and it isn't behaving as expected. I want to avoid having to write custom convert functions for my enums so I want to convert to an int and cast to...
9
by: Naomi | last post by:
I need to make software engineering decision to do with using a derived data type in a container class. So for example, if I have an Edge class, and I want to make a Edge object which contains two...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.