473,387 Members | 1,664 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,387 software developers and data experts.

difference between generics and templates

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
expects to use that exact same specialized type. Code in assembly A
creates an instance of the List<int> type and passes a reference to that
instance to code in assembly B that wishes to use its List<int> type.
Boom! At the very least, you will get a runtime type mismatch exception.
Depending on how you pass the reference, you might even get the error at
compile time. The error is because the List<int> type in assembly A is
not the same type as List<int> in assembly B."
(Taken from:
http://www.developer.com/net/cplus/a...919_3367531_1).

What does the author means by assembly? Is this a class?

So far, I understand this, the following is not possible with templates:
class A
{
public std::vector<int> myVector;

public A(std::vector<int> _myVector)
{
// do something
}
}

class B
{
public std::vector<int> myVector;
public A _a;

public B() : myVector()
{
_a = new A(myVector);
}
}

(code is not compiled!)

Is this the problem described above, or what does the author means?

Thanks for your help!
Anton
Jan 16 '06 #1
0 784

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

Similar topics

9
by: Chuck Bowling | last post by:
I assume that 2.0 will be rolled out with VS.NET 2004. Does anybody know if MS is planning to ship an STL package with it?
2
by: Mr.Tickle | last post by:
So whats the deal here regarding Generics in the 2004 release and templates currently in C++?
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 :...
11
by: herpers | last post by:
Hello, I probably don't see the obvious, but maybe you can help me out of this mess. The following is my problem: I created two classes NormDistribution and DiscDistribution. Both classes...
1
by: titan.nyquist | last post by:
"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." -...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
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,...
0
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...
0
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...

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.