Static members of template classes and static members of normal classes

Source: Internet
Author: User

A template class can also define a static member.

As with ordinary classes, defined static members must be defined once in the scope of the definition class.

Otherwise, in the link phase, the compiler cannot recognize the static data members of the class, resulting in unrecognized identifier errors.

It is important to note that each instance of the template class has its own static copy.

This is usually the case when defining static members outside of a class: Template<typename _typ> int class<_typ>::i=0;

All instances of the template class class, static member I, are initialized to zero this time.

When using static members of a template class, this is usually the case: Class::i or class obj; OBJ.I = 3;

That is, an object can invoke a public static member, or you can use a scope operator.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.