M
mathieu
I would like to know if the following operation on s2 is legal or not.
And if not what should I do instead (my data member are declared at the
begining of the struct).
I am pretty sure this is illegal, but I would like to avoid duplicating
the logic that take place when initializing s1.
Thanks for your help.
Mathieu
(*)
#include <iostream>
struct String
{
char Internal[4+1];
void Print() {
std::cout << Internal << std::endl;
}
};
int main()
{
String s1 = {"019Y"}; // give compiler error if too large
s1.Print();
String s2;
char array[] = "123D";
s2 = reinterpret_cast<String&>( array ); // is this legal
s2.Print();
return 0;
}
And if not what should I do instead (my data member are declared at the
begining of the struct).
I am pretty sure this is illegal, but I would like to avoid duplicating
the logic that take place when initializing s1.
Thanks for your help.
Mathieu
(*)
#include <iostream>
struct String
{
char Internal[4+1];
void Print() {
std::cout << Internal << std::endl;
}
};
int main()
{
String s1 = {"019Y"}; // give compiler error if too large
s1.Print();
String s2;
char array[] = "123D";
s2 = reinterpret_cast<String&>( array ); // is this legal
s2.Print();
return 0;
}