宣布班级为静态
Declaring a class as static?
背景:
我目前正在通过EDX |中级C 课程。尽管该课程是由Microsoft领导的,但并不声明您需要使用其IDE Visual Studios成功完成。我只有一个Mac,所以我完全不用担心就使用Xcode进行了介绍课程。
问题:
在中间课程的第一个模块中,它指出您可以将标题内的类声明为静态:
// Math.h
// Header file for the Math class
#pragma once
// Math class definition
static class Math
{
public:
// given base and exponent, calculate value
static int Math::pow(int base, int exp);
};
xcode标记错误,说:
'static'不允许在类型的声明中允许
根据以前提出的问题,这是不可能的混淆人们。
static
在此上下文中无效。替代方案是全静态成员,但类本身无效。
a 类似语法的使用将是:
static class Math
{
public:
// given base and exponent, calculate value
static int Math::pow(int base, int exp);
} math; // <---- note object
在这种情况下,对象math
是static
,而不是类本身。
只需在上课前删除静态关键字即可。练习中的所有内容仍然以相同的方式完全有意义。
相关文章:
- QT在错误的班级中寻找空位
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- #为""定义宏;静态";针对不同的上下文
- cmake如何在fedora工作站中找到boost静态库包
- 静态数据成员的问题-修复链接错误会导致编译器错误
- 将公共但非静态的成员函数与ALGLIB集成
- cmake在我的项目中所需的所有静态库都不成功
- C++从另一个类访问公共静态向量的正确方法是什么
- 基于boost的程序的静态链接——zlib问题
- 在静态库中嵌入类方法
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 如何在C++中获得"静态纯虚拟"功能?
- 私有类型的静态常量成员
- 使用gcc从静态链接的文件中查找可选符号
- 在 .h 文件中的类中声明静态变量和在.cpp文件中声明"global"变量有什么区别
- 如何在班级中声明和初始化静态成员
- 为什么需要在班级之外初始化非恒定静态变量
- 宣布班级为静态
- 将H5 :: CompType初始化为班级的静态成员
- 格利布的静态链接