c++;类-冲突声明错误 我刚刚开始学习C++中的类,我得到下面代码的错误:冲突声明'STD::String PixaOrth::TopgsSp'提供 < /P>
有人能解释一下我的代码有什么问题吗c++;类-冲突声明错误 我刚刚开始学习C++中的类,我得到下面代码的错误:冲突声明'STD::String PixaOrth::TopgsSp'提供 < /P>,c++,class,static,C++,Class,Static,有人能解释一下我的代码有什么问题吗 class PizzaOrder { public: //all the toppings that are offered, constant array of strings static string toppings_offered[5]; static double topping_base_cost; }; string PizzaOrder::toppings_offered = {"onions", "bell pep
class PizzaOrder
{
public:
//all the toppings that are offered, constant array of strings
static string toppings_offered[5];
static double topping_base_cost;
};
string PizzaOrder::toppings_offered = {"onions", "bell peppers", "olives", "spinach", "tomatoes"};
double PizzaOrder::topping_base_cost = 0.50;
您忘记了提供的
toppings\u
是字符串数组,而不是字符串:
string PizzaOrder::toppings_offered[5] = {"onions", ... };
// ^
// |
(顺便说一句,我希望比萨订单是订购配料,而不是提供配料。这可能是因为您的设计仍然有点混乱吗?
string PizzaOrder::toppings\u提供[5]
而不是
string PizzaOrder::toppings\u提供的
定义中必须使用与声明中相同的类型:
string PizzaOrder::toppings_offered[5] = { ... };
类型是
string[5]
,而不是string
你不能这样做。您需要通过调用
PizzaOrder myPizzaOrder = new PizzaOrder();
myPizzaOrder.topping_offered {"","",""};