468,296 Members | 1,282 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,296 developers. It's quick & easy.

What is a Traits class

mythescriptid
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
4 1598
sicarie
4,677 Expert Mod 4TB
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
9,207 Expert Mod 8TB
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
4,677 Expert Mod 4TB
Thanks weaknessforcats, as you can tell, I definitely did not know that.
May 29 '07 #4
AdrianH
1,251 Expert 1GB
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.

Similar topics

1 post views Thread by Donald 'Paddy' McCarthy | last post: by
4 posts views Thread by Alexander Stippler | last post: by
5 posts views Thread by Rex_chaos | last post: by
12 posts views Thread by Mark A. Gibbs | last post: by
4 posts views Thread by Sargon | last post: by
9 posts views Thread by Bit Byte | last post: by
4 posts views Thread by Vince C. | last post: by
2 posts views Thread by Colin J. Williams | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.