在我的班级中,我有私有成员变量“s3_client”,如下面的代码片段所示
class GpuMatcher
{
private:
Aws::SDKOptions options;
Aws::S3::S3Client s3_client;
..
public:
GpuMatcher();
..
};
要配置“s3_client”,我需要创建一些其他依赖对象,如下所示:
Aws::Client::ClientConfiguration config;
std::string region=AppContext::getProperty("region");
Aws::String aws_region(region.c_str(), region.size());
config.region=aws_region;
Aws::S3::S3Client s3_client(config); //initialize s3_client
我的问题是,如何在类构造函数中初始化它?
GpuMatcher::GpuMatcher() : options() , s3_client(???)
{
}
如果您需要将参数传递给它并存储配置(也许?):
class GpuMatcher
{
private:
Aws::SDKOptions options;
Aws::Client::ClientConfiguration config;
Aws::S3::S3Client s3_client;
static const Aws::Client::ClientConfiguration& populate_region(Aws::Client::ClientConfiguration& config);
..
public:
GpuMatcher();
..
};
然后:
GpuMatcher::GpuMatcher() : options() , s3_client(populate_region(config))
{
}
请注意此处的顺序,因为必须在客户端之前创建配置。
如果你不需要存储的配置做(如果它是构造一个传递值),不需在传递config
到populate_region
(然后它是一个create_config
)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句