Hello all,
Can somebody help me hopw to resolve teh probelm of aggregate initialisation
in c++.
Her eis the piece of code.
#include<stdio. h>
class MyTest
{
public:
DECLARE_AGGREGA TABLE (MyTest);
MyTest(float input = 0.0f):Data(inpu t){}
float Data;
};
struct MyStruct
{
MyTest a;
int b;
};
struct MyStruct test[2] = { {1.2f,1},{2.4f, 3}};
int main()
{
printf("%f\n",t est[0].a.Data);
return 0;
}
I am getting the compialtion error as follows:
error C2440: 'initializing' : cannot convert from 'const float' to 'struct
MyStruct'
No constructor could take the source type, or constructor overload
resolution was ambiguous.
And when i decalrea str4uct variable as follows:
struct MyStruct test = { 1.2f ,3 };
I am getting the following error:
error C2552: 'test' : non-aggregates cannot be initialized with initializer
list
Is there any option to use initaliser list toassign the UDTS aggregately?
Your help is needed at the earliest.
Thanks in Advance.
Raghu 3 3334
Raghu wrote: Hello all, Can somebody help me hopw to resolve teh probelm of aggregate initialisation in c++.
What is aggregate initialization anyway? Aggregation can have a lot of
meanings in different contexts, which one are you talking about?
Her eis the piece of code.
#include<stdio. h>
class MyTest { public: DECLARE_AGGREGA TABLE (MyTest);
Well, what is DECLARE_AGGREGA TEABLE? Either provide the definition of
that macro or provide the resultant (non-macro) code equivalent.
MyTest(float input = 0.0f):Data(inpu t){} float Data; };
struct MyStruct { MyTest a; int b; }; struct MyStruct test[2] = { {1.2f,1},{2.4f, 3}};
MyStruct test[] = {{MyTest(1.2f), 1}, {MyTest(2.4f), 3}}; int main() {
printf("%f\n",t est[0].a.Data); return 0; }
I am getting the compialtion error as follows:
error C2440: 'initializing' : cannot convert from 'const float' to 'struct MyStruct' No constructor could take the source type, or constructor overload resolution was ambiguous.
And when i decalrea str4uct variable as follows:
struct MyStruct test = { 1.2f ,3 };
MyStruct test = {MyTest(1.2f), 3};
I am getting the following error:
error C2552: 'test' : non-aggregates cannot be initialized with initializer list
Is there any option to use initaliser list toassign the UDTS aggregately? Your help is needed at the earliest.
I still don't get why you need a macro for this matter but if you just
change the lines to those I wrote it should be all right... Thanks in Advance. Raghu
Regards,
Ben
Raghu wrote: Hello all, Can somebody help me hopw to resolve teh probelm of aggregate initialisation in c++. Her eis the piece of code.
#include<stdio. h>
class MyTest { public: DECLARE_AGGREGA TABLE (MyTest);
What does the above line mean?
benben wrote: Raghu wrote: Hello all, Can somebody help me hopw to resolve teh probelm of aggregate initialisation in c++.
What is aggregate initialization anyway? Aggregation can have a lot of meanings in different contexts, which one are you talking about?
The C++ standard defines aggregate. MyTest is not an aggregate (has
a user-defined constructor). However MyStruct is an aggregate. A
member that is not an aggregate itself is permitted in an aggregate.
(It's not like POD's where everything contained within must also be
POD). This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Tim |
last post by:
Please advise if you can.
Presumably initialisation of members in member initialisation lists is
perfomed by 'C' run-time startup. If the CRT was never started-up would
those members be garbage? Which of these fundamental language support
features could I expect to be absent (and anything else I might have
missed):
static data zeroing...
|
by: Kiel |
last post by:
=====
My error is:
error C2512: no appropriate default constructor available
I'm trying to use the default args for class B when it is an aggregate
of class A. I could solve this problem with a point to B and
initialize it in the C'tor of A, but logically it makes sense as an
aggregate.
=====
|
by: Piotr Sawuk |
last post by:
just a quick question out of curiosity: how to initialize const arrays?
struct srat
{
long num;
ulong den;
srat(){}
}
struct collisions
|
by: MrNobody |
last post by:
I've read that the expression property for DataColumns is used to "Sets or
retrieves the expresssion used to filter rows, calculate the values in a
column, or create an aggregate column.".
I have seen examples on how to filter a column, but how would I filter out
an entire row depending on the value of a column?
For example, if I wanted...
|
by: Najib Abi Fadel |
last post by:
Hi
i have an ordered table of dates let's say:
1/1/2004
8/1/2004
15/1/2004
29/1/2004
5/2/2004
12/2/2004
| |
by: Frederick Gotham |
last post by:
I have just been reading 8.5 in the Standard, and am trying to make sense
of the different kinds of initialisations.
Up until now, I thought of an object as either NOT being initialised (i.e.
containing garbage), or being default initialised (i.e. containing the
default value for that type).
Here are some examples of the former:
struct...
|
by: Frederick Gotham |
last post by:
How do we initialise an aggregate member object of a class? The following
won't compile for me:
struct MyStruct {
int i;
double d;
};
class MyClass {
private:
|
by: Ian825 |
last post by:
I need help writing a function for a program that is based upon the various operations of a matrix and I keep getting a "non-aggregate type" error. My guess is that I need to dereference my pointers, but I'm not sure. Please help.
The code:
void equate(matrix *A, matrix *B)
{
int i, j;
assert(A.row_dim == B.col_dim && A.col_dim ==...
|
by: shapper |
last post by:
Hello,
I have the following Linq query:
var q = (from p in database.Posts
join pt in database.PostsTags on p.PostID equals
pt.PostID
join t in database.Tags on pt.TagID equals t.TagID
group t by p into pt
select new PostPaper {
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |