这个类定义的c ++等价物是什么

Kri*_*Pal 0 c++ python

我正在尝试学习C++,但我的第一语言是Python.我正在努力理解C++中的构造函数,更具体地说是变量大小的数组和字符串.有人可以编写以下类定义的C++等价物,以便我可以遵循逻辑吗?

class Fruit(object):
    def __init__(self, name, color, flavor, poisonous):
        self.name = name
        self.color = color
        self.flavor = flavor
        self.poisonous = poisonous
Run Code Online (Sandbox Code Playgroud)

hlt*_*hlt 6

class Fruit {
    std::string name;
    std::tuple<uint8_t, uint8_t, uint8_t> color; // for RGB colors
    std::string flavor; // Assuming flavor is a string
    bool poisonous;

    Fruit(const std::string& nm, const std::tuple<uint8_t, uint8_t, uint8_t>& clr, const std::string& flvr, const bool psns) : name(nm), color(clr), flavor(flvr), poisonous(psns) {}
}
Run Code Online (Sandbox Code Playgroud)

__init__函数与C++中的构造函数非常相似.因为在C++,需要指定的变量类型,我采取了一些自由在假定nameflavor都是字符串,color是值的3元组从0到255(RGB)和poisonous是一个布尔(bool)值.