小编Pet*_*etr的帖子

C++变量 - 声明和定义.遗产

让我们有一个C++对象A.它的子代可以访问A中的两个变量(VAR1和VAR2).对象B扩展A并具有一个私有变量VAR3,它还可以访问VAR1和VAR2.A/B的每个实例都有自己的变量.

这是否是声明和定义变量的正确方法?


class A {
protected:
    static std::string const VAR1;
    static std::string VAR2;
};
Run Code Online (Sandbox Code Playgroud)

A.cpp


#include "A.h"
using namespace std;
string const A::VAR1 = "blah";
string A::VAR2;
Run Code Online (Sandbox Code Playgroud)

BH


#include "A.h"
class B : public A {
private:
    static std::string VAR3;

public:
    B(std::string const v1, std::string const v2);
    void m() const;
};
Run Code Online (Sandbox Code Playgroud)

B.cpp


#include "B.h"
using namespace std;

string B::VAR3;

B::B(string const v1, string const v2) {
    VAR2 = v1;
    VAR3 = v2;
}

void B::m() const {
    // Print …
Run Code Online (Sandbox Code Playgroud)

c++ variables scope declare

6
推荐指数
1
解决办法
619
查看次数

Linux到Windows C++端口

我试图将我的C++应用程序从Linux移植到Windows(Visual C++).我只是好奇你知道任何扫描源代码并检查可能的问题的脚本/工具(例如dirent.h等).

谢谢.

c++ linux windows porting

2
推荐指数
1
解决办法
8320
查看次数

标签 统计

c++ ×2

declare ×1

linux ×1

porting ×1

scope ×1

variables ×1

windows ×1