Modern CPP Design related

L

LRS Kumar

In Section 1.4 of Alexandrescu's Modern C++ Design, he states the
following:

<quote>
1. You cannot specialize structure. Using templates alone you cannot
specialize the structure of a class (its data members). You can only
specialize only functions.
</quote>

What does the author mean by that? Wouldn't the following constitute
"specializing structure"?

template<typename T>
class A {
T t;
};

template<>
class A<int> {
float t;
std::string s;
};


Thanks in advance for your time.

Terribly confused,
LRS
 
W

Wolfgang Meyer

LRS said:
In Section 1.4 of Alexandrescu's Modern C++ Design, he states the
following:

<quote>
1. You cannot specialize structure. Using templates alone you cannot
specialize the structure of a class (its data members). You can only
specialize only functions.
</quote>

What does the author mean by that? Wouldn't the following constitute
"specializing structure"?
[...]

Yes, it does. But the point is that you have to repeat the whole class
definition while for member _functions_ you can specialize just one
function.
See:
http://groups.google.com/groups?hl=...%24dgha6%241%40ID-14036.news.dfncis.de&rnum=5

Here Alexandrescu answers exactly this questions.

Wolfgang
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top