#include<iostream> using namespace std; struct TDate { int day, month, year; void Readfromkb() { cout << "\n ENTER DAY MONTH YEAR\n"; cin >> day >> month >> year; } void print() { cout << day << month << year; } private: int ID; bool valid; }; int main() { TDate t1, t2,t3={ 1, 2, 3 }; t1.Readfromkb(); t1.print(); cin.ignore(); cin.get(); return 0; }
why am I getting error Error 1 C2440: "initializing": cannot convert from "initializer-list" to "TDate" and 2 IntelliSense: too many initialization values. When I delete bool valid and int ID, the programs work. Why is this so?
You get an error because you are trying to initialize TDatefrom the aggregate initialization list. This cannot be done if this type has private members (for example, in your case IDand valid).
TDate
ID
valid
, int TDate t1, t2, t3(1, 2, 3).
int
TDate t1, t2, t3(1, 2, 3)
t3={ 1, 2, 3 };, TDate , :
t3={ 1, 2, 3 };
TDate(int i, int i1, int i2);
, :
TDate::TDate(int i, int i1, int i2) { }
TDate t1 = TDate();
Source: https://habr.com/ru/post/1613077/More articles:Проблемы с внедрением wxpython html2.WebViewHandler и html2.WebViewFSHandler - pythonIs there a performance limitation using capture groups in the RegExp # test? - javascriptCan I run matlab on a raspberry pi? - matlabHow to create an image file and "Save to Camera Roll" - react-nativeКак перейти с Apache Kafka на Confluent Platform? - dockerHow to center images / text - htmlJava based configuration to enable spring anonymous access - java@NonNull and @Nullable annotations - does performance affect Android? - androidhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1613081/what-files-to-put-on-bitbucket-so-that-my-teams-could-use&usg=ALkJrhjAfwOv9PIoOv9GrsF7vaiasuopvQHow to generate 5 different random numbers? - javascriptAll Articles