could not convert ‘{0}’ from ‘《brace-enclosed initializer list>’ to
C + + program, using the usual initialization list today, actually reported an error
struct sales {
char bookNo;
unsigned units_sold = 0;
double revenue = 0.0;
};
int main() {
sales a = {0};
// print(cout, a);
}
error message
cpp_primer.cc:62:17: error: could not convert '{0}' from '<brace-enclosed initializer list>' to 'sales'
62 | sales a = {0};
| ^
| |
| <brace-enclosed initializer list>
The problem is that the initial value is defined in the structure. At this time, the initialization list cannot be used
Change the structure to
struct sales {
char bookNo;
unsigned units_sold;
double revenue;
};
That’s it
Summary
There are two initialization methods:
- when defining a structure, the initial value is given to initialize the list assignment OL>
The above two methods are mutually exclusive, and only one can be selected
reference material https://qa.1r1g.com/sf/ask/2644377641/
Read More:
- Array initializer is not allowed here
- error: initializer element is not constant [How to Solve]
- Coredata: error: failed to call designed initializer on nsmanagedobject
- tf.contrib.layers .xavier_ Initializer function usage
- python-TypeError: list indices must be integers, not tuple Solution
- Tensorflow ValueError: Failed to convert a NumPy array to a Tensor
- Error Code: 1055. Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated
- Summary of three methods for pandas to convert dict into dataframe
- request:fail url not in domain list or Cannot send network request to localhost
- JNI calls the add function of list in Java to flash back
- Python error TypeError:can ‘t convert complex to float
- How to convert iconfont to PNG transparent image
- List indexes must be integers or slices, not tuple solution
- Solve the problem that vscode cannot convert the easy less plug-in to the less expression value
- “Typeerror: List indexes must be integers or slices, not STR” about error reporting solutions
- How to convert audio to subtitle (text) with Python?
- Convert document txt to UNIX code under Linux
- How to Use ffmpeg to convert MP4 and other formats to MP3 format
- JSON and map convert to each other (using fastjson)
- ERROR:expected initializer before “int”