The const object is static by default, not extern

Source: Internet
Author: User
const and static variables, which can be placed in the header file

const objects are static by default, not extern, so they are declared and defined in the header file. Multiple CPP references the same header file and is not aware of each other, so it does not cause duplicate definitions.

class definition, which can be placed in a header file

When you create an object with a class, the compiler knows how the object is laid out to allocate memory, so the definition of the class needs to be in the header file. In general, we put the definition of the member function within the class in the CPP file, but if the function declaration + definition is done directly in class, this function will be treated as inline by the compiler, thus satisfying the rule that the above inline function can be placed in the header file. But if the declaration and definition are implemented separately, but all are placed in the header file, then the duplicate definition will be reported!!

https://zybuluo.com/uuprince/note/81709

The const object is static by default, not extern

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.