D
drowned
all right, check it out... I've got a practice exercise from "thinking
in c++" whose answer isn't covered in the annotated solutions guide,
so I'm trying to handle it, but I don't understand what I'm doing
wrong. Here is the exercise:
27. Create a const array of double and a volatile array of double.
Index through each array and use const_cast to cast each element to
non-const and non-volatile, respectively, and assign a value to each
element. //end exercise
now, here's what I came up with:
#include <iostream>
using namespace std;
int main() {
const double cd[3] = {3,3,3};
volatile double vd[3];
for(int i=0;i<3;i++) {
double t1 = const_cast<double>(cd);
double t2 = const_cast<double>(vd);
cd = t1;
vd = t2;
cout << "cd[" << i << "] = " << cd << endl;
cout << "vd[" << i << "] = " << vd << endl;
}
}
when I try to compile, I get a bunch of errors about invalid use of
const_char with type 'double'. I've tried a bunch of variations on
the two lines that include const_char, but none of them work... I
obviously don't understand this concept. Please help.
in c++" whose answer isn't covered in the annotated solutions guide,
so I'm trying to handle it, but I don't understand what I'm doing
wrong. Here is the exercise:
27. Create a const array of double and a volatile array of double.
Index through each array and use const_cast to cast each element to
non-const and non-volatile, respectively, and assign a value to each
element. //end exercise
now, here's what I came up with:
#include <iostream>
using namespace std;
int main() {
const double cd[3] = {3,3,3};
volatile double vd[3];
for(int i=0;i<3;i++) {
double t1 = const_cast<double>(cd);
double t2 = const_cast<double>(vd);
cd = t1;
vd = t2;
cout << "cd[" << i << "] = " << cd << endl;
cout << "vd[" << i << "] = " << vd << endl;
}
}
when I try to compile, I get a bunch of errors about invalid use of
const_char with type 'double'. I've tried a bunch of variations on
the two lines that include const_char, but none of them work... I
obviously don't understand this concept. Please help.