473,378 Members | 1,531 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.

difference between c++ templates & c# generics

"At the implementation level, the primary difference is that C#
generic type substitutions are performed at runtime and generic type
information is thereby preserved for instantiated objects."
- http://msdn2.microsoft.com/en-us/library/c6cyy67b.aspx

Wonder if someone could elaborate this difference to me. I understand
performing substitutions at runtime is slow. But, it implies in c++
templates, the type information is not preserved for instantiated
objects. Is this true?

Titan

Apr 4 '07 #1
1 1726
ti***********@gmail.com wrote:
"At the implementation level, the primary difference is that C#
generic type substitutions are performed at runtime and generic type
information is thereby preserved for instantiated objects."
- http://msdn2.microsoft.com/en-us/library/c6cyy67b.aspx

Wonder if someone could elaborate this difference to me. I understand
performing substitutions at runtime is slow. But, it implies in c++
templates, the type information is not preserved for instantiated
objects. Is this true?
In C# the generics source code is actually compiled to generics
binary code that can be used by external code.

In C++ the template source can not be independent compiled
and is compiled into the binary code of using it.

The C++ way is not very elegant. If you have a template
class and you use it for 3 types in each of 10 source
files you actually end up with 30 copies of the code.

The C++ way is very practical, because in c# you have to
declare the generic type as inherit from this and that to be
able to use it for anything, while in C++ you do not
need to do anything, because the operations on the substituted
types are checked at compile time.

Arne
Apr 4 '07 #2

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

Similar topics

3
by: Andre | last post by:
Hi, I've built a math library that does some matrix multiplications and other linear algebric functions. I read some place about generics or class templates and I was wondering if this will help...
7
by: Bob Weiner | last post by:
Hi, Forgive me if this has already been discussed but does C# have a construct like C++ templates? bob
7
by: yufufi | last post by:
lets say we have a 'shape' class which doesn't implement IComparable interface.. compiler doesn't give you error for the lines below.. shape b= new shape(); IComparable h; h=(IComparable)b;...
2
by: Mr.Tickle | last post by:
So whats the deal here regarding Generics in the 2004 release and templates currently in C++?
4
by: Ana Farcas via .NET 247 | last post by:
hello, i have an old library i need to port to .net. the old library is written in visual c++ 6.0 and uses templated classes. if i compile the library (after having gone through the conversion...
11
by: Peter Oliphant | last post by:
Is there any plan to support templates with managed code in the (near) future? For instance, VS.NET 2005... : )
9
by: Anton Berg | last post by:
Hi, I suppose this question was already often asked and in fact I am not interested in a complete overview of the differences, cause I already found them on several pages. In fact, what I...
2
by: Zoran Stipanicev | last post by:
I'm trying to port simple expression template to generics but I get some strange errors. The code is shown below and the errors are: (1) 'l_' : is not a member of 'IExpresion' (2) syntax error :...
26
by: puzzlecracker | last post by:
Team, C++ has been around since 1986, why templates are still regarded is a new feature by most compiler vendors and not fully supported (for example export feature). Look at other popular...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.