C++ Call default constructor for Struct and its inherited members [duplicate]
This question already has an answer here:
Why can I not brace initialize a struct derived from another struct?
1 answer
I'd like to be able to initialize an object with the following syntax in C++14:
const auto data1 = DataOne{1, 2, 3};
const auto data2 = DataTwo{1, 2, 3, 4, 5};
const auto data3 = DataThree{1, 2, 3, 4, 5, 6, 7};
Which gives me the following error message:
error msg `error: no matching function for call to ‘DataThree::DataThree(<brace-enclosed initializer list>)’`
With the types defined as:
struct DataOne
{
int a;
int b;
int c;
};
struct DataTwo : DataOne
{
int d;
int e;
};
struct DataThree : DataTwo
{
int f;
int g;
};
I dont want to use the struct in struct method because then I will need to call params through double or triple dots which I dont want to use because all the members are equal important and it will look bad to read.
c++ initialization c++14
marked as duplicate by Matthieu Brucher, rubenvb
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 12:54
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Why can I not brace initialize a struct derived from another struct?
1 answer
I'd like to be able to initialize an object with the following syntax in C++14:
const auto data1 = DataOne{1, 2, 3};
const auto data2 = DataTwo{1, 2, 3, 4, 5};
const auto data3 = DataThree{1, 2, 3, 4, 5, 6, 7};
Which gives me the following error message:
error msg `error: no matching function for call to ‘DataThree::DataThree(<brace-enclosed initializer list>)’`
With the types defined as:
struct DataOne
{
int a;
int b;
int c;
};
struct DataTwo : DataOne
{
int d;
int e;
};
struct DataThree : DataTwo
{
int f;
int g;
};
I dont want to use the struct in struct method because then I will need to call params through double or triple dots which I dont want to use because all the members are equal important and it will look bad to read.
c++ initialization c++14
marked as duplicate by Matthieu Brucher, rubenvb
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 12:54
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
So what's the error message? Which C++ standard can you use?
– Matthieu Brucher
Nov 26 '18 at 12:38
Perfectly valid C++17, there is nothing to reproduce.
– Matthieu Brucher
Nov 26 '18 at 12:41
1
A relevant question for you: stackoverflow.com/questions/16983539/…
– bracco23
Nov 26 '18 at 12:43
add a comment |
This question already has an answer here:
Why can I not brace initialize a struct derived from another struct?
1 answer
I'd like to be able to initialize an object with the following syntax in C++14:
const auto data1 = DataOne{1, 2, 3};
const auto data2 = DataTwo{1, 2, 3, 4, 5};
const auto data3 = DataThree{1, 2, 3, 4, 5, 6, 7};
Which gives me the following error message:
error msg `error: no matching function for call to ‘DataThree::DataThree(<brace-enclosed initializer list>)’`
With the types defined as:
struct DataOne
{
int a;
int b;
int c;
};
struct DataTwo : DataOne
{
int d;
int e;
};
struct DataThree : DataTwo
{
int f;
int g;
};
I dont want to use the struct in struct method because then I will need to call params through double or triple dots which I dont want to use because all the members are equal important and it will look bad to read.
c++ initialization c++14
This question already has an answer here:
Why can I not brace initialize a struct derived from another struct?
1 answer
I'd like to be able to initialize an object with the following syntax in C++14:
const auto data1 = DataOne{1, 2, 3};
const auto data2 = DataTwo{1, 2, 3, 4, 5};
const auto data3 = DataThree{1, 2, 3, 4, 5, 6, 7};
Which gives me the following error message:
error msg `error: no matching function for call to ‘DataThree::DataThree(<brace-enclosed initializer list>)’`
With the types defined as:
struct DataOne
{
int a;
int b;
int c;
};
struct DataTwo : DataOne
{
int d;
int e;
};
struct DataThree : DataTwo
{
int f;
int g;
};
I dont want to use the struct in struct method because then I will need to call params through double or triple dots which I dont want to use because all the members are equal important and it will look bad to read.
This question already has an answer here:
Why can I not brace initialize a struct derived from another struct?
1 answer
c++ initialization c++14
c++ initialization c++14
edited Nov 26 '18 at 12:48
YSC
25.5k557112
25.5k557112
asked Nov 26 '18 at 12:37
PiodoPiodo
16612
16612
marked as duplicate by Matthieu Brucher, rubenvb
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 12:54
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Matthieu Brucher, rubenvb
StackExchange.ready(function() {
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function() {
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function() {
$hover.showInfoMessage('', {
messageElement: $msg.clone().show(),
transient: false,
position: { my: 'bottom left', at: 'top center', offsetTop: -7 },
dismissable: false,
relativeToBody: true
});
},
function() {
StackExchange.helpers.removeMessages();
}
);
});
});
Nov 26 '18 at 12:54
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
So what's the error message? Which C++ standard can you use?
– Matthieu Brucher
Nov 26 '18 at 12:38
Perfectly valid C++17, there is nothing to reproduce.
– Matthieu Brucher
Nov 26 '18 at 12:41
1
A relevant question for you: stackoverflow.com/questions/16983539/…
– bracco23
Nov 26 '18 at 12:43
add a comment |
1
So what's the error message? Which C++ standard can you use?
– Matthieu Brucher
Nov 26 '18 at 12:38
Perfectly valid C++17, there is nothing to reproduce.
– Matthieu Brucher
Nov 26 '18 at 12:41
1
A relevant question for you: stackoverflow.com/questions/16983539/…
– bracco23
Nov 26 '18 at 12:43
1
1
So what's the error message? Which C++ standard can you use?
– Matthieu Brucher
Nov 26 '18 at 12:38
So what's the error message? Which C++ standard can you use?
– Matthieu Brucher
Nov 26 '18 at 12:38
Perfectly valid C++17, there is nothing to reproduce.
– Matthieu Brucher
Nov 26 '18 at 12:41
Perfectly valid C++17, there is nothing to reproduce.
– Matthieu Brucher
Nov 26 '18 at 12:41
1
1
A relevant question for you: stackoverflow.com/questions/16983539/…
– bracco23
Nov 26 '18 at 12:43
A relevant question for you: stackoverflow.com/questions/16983539/…
– bracco23
Nov 26 '18 at 12:43
add a comment |
1 Answer
1
active
oldest
votes
As of C++17, the syntax you wish for is valid:
const auto data3 = DataThree{1, 2, 3, 4, 5, 6, 7};
Live demo
Before that, aggregate initialization would be illegal per [dcl.init.aggr]/1
:
An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As of C++17, the syntax you wish for is valid:
const auto data3 = DataThree{1, 2, 3, 4, 5, 6, 7};
Live demo
Before that, aggregate initialization would be illegal per [dcl.init.aggr]/1
:
An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).
add a comment |
As of C++17, the syntax you wish for is valid:
const auto data3 = DataThree{1, 2, 3, 4, 5, 6, 7};
Live demo
Before that, aggregate initialization would be illegal per [dcl.init.aggr]/1
:
An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).
add a comment |
As of C++17, the syntax you wish for is valid:
const auto data3 = DataThree{1, 2, 3, 4, 5, 6, 7};
Live demo
Before that, aggregate initialization would be illegal per [dcl.init.aggr]/1
:
An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).
As of C++17, the syntax you wish for is valid:
const auto data3 = DataThree{1, 2, 3, 4, 5, 6, 7};
Live demo
Before that, aggregate initialization would be illegal per [dcl.init.aggr]/1
:
An aggregate is an array or a class (Clause 9) with no user-provided constructors (12.1), no private or protected non-static data members (Clause 11), no base classes (Clause 10), and no virtual functions (10.3).
answered Nov 26 '18 at 12:40
YSCYSC
25.5k557112
25.5k557112
add a comment |
add a comment |
1
So what's the error message? Which C++ standard can you use?
– Matthieu Brucher
Nov 26 '18 at 12:38
Perfectly valid C++17, there is nothing to reproduce.
– Matthieu Brucher
Nov 26 '18 at 12:41
1
A relevant question for you: stackoverflow.com/questions/16983539/…
– bracco23
Nov 26 '18 at 12:43