php 初始化顺序,C全局变量和初始化顺序

比方说,我有一个简单的代码:

Main.cpp的

#include "A.h"

// For several reasons this must be a global variable in the project

A a1;

int _tmain(int argc, _TCHAR* argv[])

{

// Another stuff

return 0;

}

#pragma once

#include

class A

{

private:

// The following works normal if we use simple types like int and etc.

static std::string myString;

public:

A();

};

A.cpp

#include "stdafx.h"

#include "A.h"

// This executes after A::A(), so we are losing all the modifyed content

// If we skip the ="test" part, the string is going to be empty

std::string A::myString = "test";

A::A()

{

// Here myString == ""

myString += "1";

}

问题很明显:在这种情况下,我不能在类A的构造函数中使用静态变量,因为它们不保存更改.虽然我需要它们才能处理一些数据.

拜托,建议我一个解决方案.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值