In the future, remember that it is best to post a complete program (headers,main,etc) so that we can easily run (or try to compile) it.
The compiler does not know how to set a Planet to a char. If you want to be able to assign a char to a Planet then you need to define an operator= overload for that purpose.
Alternatively if the char that Planet stores is public then you can directly assign to it:
Code:
planets[p].ch = alpha[p];
Here's the operator= overload (and an operator<< overload for output).
Code:
#include <iostream>
using namespace std;
class Planet {
char ch;
public:
Planet() : ch(0) {}
Planet& operator=(char c) { ch = c; return *this; }
friend ostream& operator<<(ostream& out, const Planet& p) {
return out << p.ch;
}
};
int main() {
char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVQXYZ";
int nPlanets = sizeof(alpha) - 1;
Planet *planets = new Planet[nPlanets];
for (int p = 0; p < nPlanets; p++)
planets[p] = alpha[p];
for (int p = 0; p < nPlanets; p++)
cout << planets[p] << '\n';
delete[] planets;
}