0
I have been learning c++ for long now but error messages always pops up when I ever I write a program on my compiler
4 odpowiedzi
+ 3
Did you add headers and main? in this way
#include <iostream>
using namespace std;
int main() {
union numericUnion{
int intValue;
long longValue;
double doubleValue;
};
numericUnion myUnion;
myUnion.intValue = 3;
cout << myUnion.intValue << endl;
myUnion.doubleValue = 4.5;
cout << myUnion.doubleValue << endl;
cout << myUnion.intValue;
cout << endl;
return 0;
}
+ 2
Have you made sure to place the return 0? , As well as (;) and (:), naming the first letters of the classes with capital letters.
0
yeah thanks please refer to my second question
0
1. union numericUnion
2. {
3. int intValue;
4. long longValue;
5. double doubleValue;
6. };
7. numericUnion myUnion;
8. myUnion.intValue = 3;
9. cout << myUnion.intValue << endl;
10. myUnion.doubleValue = 4.5;
11. cout << myUnion.doubleValue << endl;
12. cout << myUnion.intValue;
13. cout << endl;