473,769 Members | 4,591 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1763
ti***********@g mail.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
3203
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 me in any way? I have structures and classes with the same logic but that which deal with different types. Moreover, I would like to know if there are any performance benifits or drawbacks and how templates are or can be important to numerical...
7
1606
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
3678
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; but it complains for the following lines
2
3104
by: Mr.Tickle | last post by:
So whats the deal here regarding Generics in the 2004 release and templates currently in C++?
4
1174
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 wizard), i get errors with the definitions of the templated classes. below are some examples. template<class base, class client> templated_class_name<base,client>::pointer_to_templated_class_member*...
11
1825
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
2344
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 want to know is the following. What is meant by: "Here's a subtle point, but it's a direct result of how types are identified in .NET. Let's say that C++ code in assembly A has used a List<int> template specialization and that C++ code in assembly B
2
1274
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 : '(' generic <class Lhs, class Rhs> where Lhs:IExpresion where Rhs:IExpresion ref struct Expression : public DotNetMat::IExpresion
26
231
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 languages -- say Java, CSharp --and templates , also known as generics, are fully implemented and supported in latest releases. Yes, in C++ they are implemented differently, yet not better. Then why C++ is so lagging behind. Can't we get ourself...
0
9590
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9424
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10051
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.