By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,905 Members | 1,293 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,905 IT Pros & Developers. It's quick & easy.

What is a Traits class

mythescriptid
P: 15
Hi,

I'm trying to understand what a Traits class and when/how it is used. I have read some definitions on different sites but failed to understand the real use ;(!. Can someone explain with a simple definition and example please.

Thanks in advance.

Hari
May 28 '07 #1
Share this Question
Share on Google+
4 Replies


sicarie
Expert Mod 2.5K+
P: 4,677
Hi,

I'm trying to understand what a Traits class and when/how it is used. I have read some definitions on different sites but failed to understand the real use ;(!. Can someone explain with a simple definition and example please.

Thanks in advance.

Hari
Just as a guess based off the name, I would guess that it is a class that contains "traits" of another object - or methods that would affect how it behaved. Is this what you thought, or is there a specific "Traits" class I'm unaware of?
May 29 '07 #2

weaknessforcats
Expert Mod 5K+
P: 9,197
The STL traits class is the type used to specialize the STL template. So, char or int, etc. are traits. The STL templates use a traits rather than a T. By doing this, you can code traits methods for your type, which you cannot do with a simple placeholder like T.
May 29 '07 #3

sicarie
Expert Mod 2.5K+
P: 4,677
Thanks weaknessforcats, as you can tell, I definitely did not know that.
May 29 '07 #4

AdrianH
Expert 100+
P: 1,251
Look up SFINAE (Substitution Error Is Not An Error) for more information.


Adrian
May 29 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.