T
Tony Young
Hi,
The following code will have a compile error unless I remove "int *p"
from class D (the error message is attached below). But I do need the
*p. Someone suggested to change the initialization code to
"S s[] = {D(d1, 3), D(d2, 4)};" assuming the constructor is provided.
Is this the only way to resolve this problem? I prefer to modify class
D and keep the initialization code intact. Would it be possible? Any
help is much appreciated. Thanks. Tony
class D
{
int *p;
};
struct S
{
D d;
int x;
};
int main(int argc, char* argv[])
{
D d1, d2;
...
S s[] = {{d1, 3}, {d2, 4}};
return 1;
}
Ps.
The error message:
cannot convert from 'class D' to 'struct S'
No constructor could take the source type, or constructor overload
resolution was ambiguous
The following code will have a compile error unless I remove "int *p"
from class D (the error message is attached below). But I do need the
*p. Someone suggested to change the initialization code to
"S s[] = {D(d1, 3), D(d2, 4)};" assuming the constructor is provided.
Is this the only way to resolve this problem? I prefer to modify class
D and keep the initialization code intact. Would it be possible? Any
help is much appreciated. Thanks. Tony
class D
{
int *p;
};
struct S
{
D d;
int x;
};
int main(int argc, char* argv[])
{
D d1, d2;
...
S s[] = {{d1, 3}, {d2, 4}};
return 1;
}
Ps.
The error message:
cannot convert from 'class D' to 'struct S'
No constructor could take the source type, or constructor overload
resolution was ambiguous