die Zuweisung einer const char-array ein char-array

Also ich habe eine Klasse, E-Mail, mit einer Klasse, die Daten-Mitglied, char Typ[30]; und static const char FIRST_CLASS[]; außerhalb der Klasse definition, die ich initialisieren FIRST_CLASS [], um "Erste Klasse".

In meinem Standard-Mail-Konstruktor möchte ich type auf FIRST_CLASS[] kann aber nicht scheinen, um herauszufinden, einen Weg, dies zu tun. Hier der code (etwas gekürzt, damit nicht zu belästigen Sie mit Sachen die Sie nicht brauchen)

#include "stdafx.h"
#include <iostream>
#include <iomanip>   
#include <cstring>
#include <string>

using namespace std;
class Mail
{
public:
    Mail();
    Mail(const char* type, double perOunceCost, int weight);
    Mail(const Mail& other);

    ~Mail()
    { }

private:
    static const int TYPE_SIZE = 30;
    static const char FIRST_CLASS[];
    static const double FIXED_COST;
    static const int DEFAULT_WEIGHT = 1;

    char type[TYPE_SIZE];
    int weight;
    double perOunceCost;
};

const char Mail::FIRST_CLASS[] = "First Class";
const double Mail::FIXED_COST = 0.49;

//default
Mail::Mail()
{
    weight = DEFAULT_WEIGHT;
    perOunceCost = FIXED_COST;
    type = FIRST_CLASS;
}

und hier ist der Fehler:

1   error C2440: '=' : cannot convert from 'const char [12]' to 'char [30]'
2   IntelliSense: expression must be a modifiable lvalue
  • welche Fehlermeldung erhalten Sie?
  • aktualisiert mit dem Fehler, danke für die Erinnerung
  • Warum sind Sie mithilfe von arrays? Warum nicht std::string?
InformationsquelleAutor jacksonSD | 2014-05-28
Schreibe einen Kommentar