`
runfeel
  • 浏览: 935817 次
文章分类
社区版块
存档分类
最新评论

Something about static Methods in C++ you should know

 
阅读更多
1.
It's not allowed to declare staticmethods as const.
The non-static versions of the methods can be marked as const.


2.
The static methods are scoped by the name of the class in which they are defined, but are notmethods that apply to a specific object.

In C++,you cannot override a static method.

First of all,a method cannot be both static and virtual.

If you have a staticmethod in your subclass with the same name as a static method in your superclass, you actuallyhave two separate methods. These two methods are in no way related.

class SuperStatic
{
public:
static void beStatic()
{
cout << "SuperStatic being static." << endl;
}
};

class SubStatic : public SuperStatic
{
public:
static void beStatic()
{
cout << "SubStatic keepin' it static." << endl;
}
};

SuperStatic::beStatic();
SubStatic::beStatic();

The results:

SuperStatic being static.
SubStatic keepin' it static.

SubStatic mySubStatic;
SuperStatic& ref = mySubStatic;
mySubStatic.beStatic();
ref.beStatic();

The results:
SubStatic keepin' it static.
SuperStatic being static.


分享到:
评论

相关推荐

    migong.rar_Something About You

    标题 "migong.rar_Something About You" 暗示我们关注的是一个关于编程学习的压缩包,特别是C和C++语言,以及它们在数据结构方面的应用。描述中提到的 "c and c++ through it you will realize something about data...

    tema.rar_Something About You

    【标题】"tema.rar_Something About You" 提到的主题涉及到创建和管理动物园的相关知识,而"Something About You"可能是指个人在这个过程中的角色或特殊经验。从描述中我们可以推测,这个压缩包可能包含了关于如何...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    Note: If you use a symbol Foo in your source file, you should bring in a definition for Foo yourself, either via an #include or via a forward declaration. Do not depend on the symbol being brought in ...

    Selected.Topics.in.Cplusplus.15117

    You need to know how and when you should use them. Then you have virtual functions and virtual tables and virtual pointers. When you know these core concepts C++ becomes a powerful language to use ...

    java_FAQ.rar_Something About You

    "java_FAQ.rar_Something About You" 提供的"java FAQ.pdf"很可能包含了一系列关于Java编程的常见问题与解答,帮助开发者解决他们在学习和实践中遇到的问题。下面我们将深入探讨一些Java的核心知识点。 1. **Java...

    Something about Moblin 2.0

    Something about Moblin 2.0

    一步一步跟我学API.rar_API_Something About You_vss

    在本资源"一步一步跟我学API.rar_API_Something About You_vss"中,我们可以深入学习API(Application Programming Interface)的相关知识,这将涵盖API的基本概念、类型、用途以及如何使用版本控制系统如VSS...

    Turbo C++ 3.0[DISK]

    In general, any selection you make of something installed earlier will cause an overwrite of the earlier version without prompting. You should read the rest of this README file to get further ...

    Something About Nginx

    Something About Nginx

    Learn.Cplusplus.In.A.DAY.1519318588.epub

    This crash course about C++ programming is not only going to teach you the basics of C++ in a didactic way, furthermore, you will learn C++ language WHEN you want, and more important, WHERE you want ...

    The Art of Unix Programming

    You should read this book if you are a C, C++ or Java programmer with experience on other operating systems who is about to start a Unix-based project. You should read this book if you are a Unix user...

    Turbo C++ 3.00[DISK]

    In general, any selection you make of something installed earlier will cause an overwrite of the earlier version without prompting. You should read the rest of this README file to get further ...

    something about UNCTAD

    SOMETHING ABOUT UNCTAD, UNCTAD IS A INTERNATIONAL ORGANISITION ,THIS PPT IS A SAMPLE INTRODUCTION ABOUT IT

    Natural Language Processing in Python 【2016】

    Did you know people have already used Twitter to determine the current sentiment about a particular company to decide whether or not they should buy or sell stocks? Having a machine that can decide ...

    Optimized C++(O'Reilly,2016)

    This practical guide teaches developers performance-tuning principles that enable optimization in C++. You'll learn how to make code that already embodies best practices of C++ design run faster and ...

    something about javaScript

    1. **语法结构**:JavaScript基于ECMAScript规范,其语法类似C++和Java,但更为灵活。它支持变量、常量、数据类型(包括字符串、数字、布尔、对象、数组等)、运算符以及流程控制语句(如if-else、switch、for、...

    Laravel Application Development Blueprints

    You will also learn about both basic and advanced usage of Laravel’s built-in methods, which will come in handy for your project. Also, you will learn how to extend the current libraries with the ...

    Win32 API 函数大全使用详解 .rar_81I_API_Something About You_Win32 API_Wi

    《Win32 API 函数大全使用详解》是深入理解Windows操作系统编程的重要参考资料,它涵盖了大量用于构建Windows应用程序的函数和接口。Win32 API(Application Programming Interface)是Microsoft为开发者提供的一个...

Global site tag (gtag.js) - Google Analytics