Its very simple but Iam unable to remove error. I want to store integer value in complex variable.
int int2 =2;
comp *cal = int2;
Thanks
Its very simple but Iam unable to remove error. I want to store integer value in complex variable.
int int2 =2;
comp *cal = int2;
Thanks
If you're using standard complex numbers (that is, comp
is an alias for std::complex<something>
):
comp cal = int2;
If comp
isn't a standard complex type, then we'll need to see how it's defined; there's no way to guess how it might work.
UPDATE: Regarding your comment: since it's a custom aggregate type, and assuming Q
is the real part:
comp cal = {0, int2};
although you really should consider using standard types instead.
Regarding the rest of your comment: Why on earth do you have to use a pointer? That's insane. But if you really need one:
comp cal_ = {0, int2};
comp *cal = &cal_;
or if you need dynamic allocation for some reason (which you almost certainly don't; and if you do, you should be using smart pointers not raw pointers):
comp *cal = new comp{0, int2};
// and don't forget to delete it when you've finished with it
delete cal;
or if you're stuck with the pre-2011 language:
comp *cal = new comp;
cal->I = 0;
cal->Q = int2;
But to reiterate, whatever you think you have to do, you almost certainly don't want a pointer here.