1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// i use dev c++ 5.6.3
//similar error on code block ide
#include <iostream>
#include<string>
using namespace std;
union myu{
string name;
int age;
};
int main()
{
myu uob;
uob.age=35;
cout<<uob.age;
return 0;
}
| |
built time error:
G:\c-pro\Untitled1.cpp In function 'int main()':
15 5 G:\c-pro\Untitled1.cpp [Error] use of deleted function 'myu::myu()'
6 7 G:\c-pro\Untitled1.cpp [Note] 'myu::myu()' is implicitly deleted because the default definition would be ill-formed:
7 8 G:\c-pro\Untitled1.cpp [Error] union member 'myu::name' with non-trivial 'std::basic_string<_CharT, _Traits, _Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
15 5 G:\c-pro\Untitled1.cpp [Error] use of deleted function 'myu::~myu()'
6 7 G:\c-pro\Untitled1.cpp [Note] 'myu::~myu()' is implicitly deleted because the default definition would be ill-formed:
7 8 G:\c-pro\Untitled1.cpp [Error] union member 'myu::name' with non-trivial 'std::basic_string<_CharT, _Traits, _Alloc>::~basic_string() [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]'
I think it is related with gcc compiler.
how to declare and access union in gcc compiler?
I need your suggestion.