私はC++のクラスを理解し、Pythonで見たいくつかの同様のクラスを開発しようとしています。コードは次のとおりです。
#include <iostream>
#include <cmath>
using namespace std;
/*============================================================================*/
/* Define types
/*============================================================================*/
class none_type;
class bool_type;
class int_type;
struct identifier;
/*============================================================================*/
/* Define none type
/*============================================================================*/
class none_type {
public:
none_type() { /* constructor */ };
~none_type() { /* destructor */ };
}; /* none_type */
/*============================================================================*/
/* Define bool type
/*============================================================================*/
class bool_type {
private:
bool base;
public:
bool_type() { base = false; };
~bool_type() { /* destructor */ };
bool_type(bool init) { base = bool(init); };
bool_type(int init) { base = bool(init); };
bool_type(long init) { base = bool(init); };
bool_type(float init) { base = bool(init); };
bool_type(double init) { base = bool(init); };
bool_type(bool_type init) { base = bool(init.base); };
bool_type(int_type init) { base = bool(init.base); };
int get() { cout << base << endl; };
}; /* bool_type */
/*============================================================================*/
/* Define int type
/*============================================================================*/
class int_type {
private:
long base;
public:
int_type() { base = 0; };
~int_type() { /* destructor */ };
int_type(bool init) { base = long(init); };
int_type(int init) { base = long(init); };
int_type(long init) { base = long(init); };
int_type(float init) { base = long(init); };
int_type(double init) { base = long(init); };
int_type(bool_type init) { base = long(init.base); };
int_type(int_type init) { base = long(init.base); };
int get() { cout << base << endl; };
}; /* int_type */
コンパイルしようとすると、g++
自分の型を使用するすべてのコンストラクターが無効であることがわかります。何が悪いのか説明してもらえますか?クラスのプロトタイプを定義しましたが、他に何をすべきですか?前もって感謝します!