For the code below, I get the following messages. These are:
1>c:\users\s1\desktop\c++folder\pr5\pr5\pr5.cpp(11): error C2078: too many initializers
1>c:\users\s1\desktop\c++folder\pr5\pr5\pr5.cpp(13): error C2143: syntax error : missing ';' before '.'
1>c:\users\s1\desktop\c++folder\pr5\pr5\pr5.cpp(13): error C2373: 'newBean' : redefinition; different type modifiers
1>c:\users\s1\desktop\c++folder\pr5\pr5\pr5.cpp(12) : see declaration of 'newBean'
1>c:\users\s1\desktop\c++folder\pr5\pr5\pr5.cpp(14): error C2143: syntax error : missing ';' before '.'
This is the code below. How can I please fix the code ? I have made the struct members to be static const.
#include <iostream>
#include <string>
using namespace std;
struct coffeeBean
{
static const string name;
static const string country;
static const int strength;
};
coffeeBean myBean = {"yes", "hello", 10 };
coffeeBean newBean;
const string newBean.name = "Flora";
const string newBean.country = "Mexico";
const int newBean.strength = 9;
int main( int argc, char ** argv ) {
cout << "Coffee bean " + newBean.name + " is from " + newBean.country << endl;
system("pause");
return 0;
}
staticmeans that only one, global instance of that member exists for all objects. Therefore eachcoffeeBeancannot have its own name.