6

ここでの私にとっての非常に単純なタスクであり、なぜこれが問題を引き起こすのかわかりません。すでに与えられているヘッダーと宣言を使用して、2つのモックアップクラスをメソッドにロジックなしでコンパイルしようとしています。正直なところ、これは何よりも切り貼りの仕事ですが、それでも私はこの黄金の愛の塊に出くわしました-

cbutton.cpp:11:44: error: default argument given for parameter 4 of ‘cio::CButton::CButton(const char*, int, int, bool, const char*)’ [-fpermissive]
cbutton.h:7:5: error: after previous specification in ‘cio::CButton::CButton(const char*, int, int, bool, const char*)’ [-fpermissive]
cbutton.cpp:11:44: error: default argument given for parameter 5 of ‘cio::CButton::CButton(const char*, int, int, bool, const char*)’ [-fpermissive]
cbutton.h:7:5: error: after previous specification in ‘cio::CButton::CButton(const char*, int, int, bool, const char*)’ [-fpermissive]
cbutton.cpp:19:41: error: default argument given for parameter 1 of ‘void cio::CButton::draw(int)’ [-fpermissive]
cbutton.h:11:10: error: after previous specification in ‘virtual void cio::CButton::draw(int)’ [-fpermissive]
cbutton.cpp:53:29: error: ‘virtual’ outside class declaration

これが私が扱っているファイルです。いつものように、みんなありがとう!

#include "cfield.h"

namespace cio{
  class  CButton: public CField{

  public:
    CButton(const char *Str, int Row, int Col, 
            bool Bordered = true,
            const char* Border=C_BORDER_CHARS);
    virtual ~CButton();
    void draw(int rn=C_FULL_FRAME);
    int edit();
    bool editable()const;
    void set(const void* str);
  };
}    




#include "cbutton.h"

namespace cio {  

  CButton::CButton(const char *Str, int Row, int Col, 
          bool Bordered = true,
          const char* Border=C_BORDER_CHARS){

  }

  void CButton::draw(int rn=C_FULL_FRAME){

  }

  int CButton::edit(){

    return 0;
  }

  bool CButton::editable()const {

  return false;
  }

  void CButton::set(const void* str){

  }

  virtual CButton::~CButton(){

  }
}
4

3 に答える 3

19

関数の定義でデフォルトの引数を指定しましたが、クラス宣言ではすでにデフォルトの引数がありました。デフォルトの引数は、クラス宣言または関数定義で宣言できますが、両方を宣言することはできません。

編集:あなたのエラーの終わりを逃した:error: ‘virtual’ outside class declaration。これはかなり明確なコンパイラエラーです。virtualキーワードは関数定義ではなくクラス宣言に属しています。デストラクタの定義から削除するだけです。

修正されたソース:

namespace cio {  

  CButton::CButton(const char *Str, int Row, int Col, 
          bool Bordered, // No default parameter here,
          const char* Border){ // here,

  }

  void CButton::draw(int rn){ // and here

  }

  CButton::~CButton(){ // No virtual keyword here

  }
}
于 2012-11-08T18:39:48.123 に答える
2

関数を定義するときに、デフォルトの引数を繰り返すことはできません。それらは宣言にのみ属します。(実際のルールはそれほど単純ではありません。定義も定義になる可能性があるためですが、アイデアは得られます...)

于 2012-11-08T18:39:45.567 に答える
1

関数定義にデフォルトパラメータを含めないでください。デフォルト値を含める必要があるのはプロトタイプだけです。

#include "cbutton.h"

namespace cio {  

  CButton::CButton(const char *Str, int Row, int Col, 
          bool Bordered,
          const char* Border){ //remove in def

  }

  void CButton::draw(int rn){

  }
于 2012-11-08T18:39:57.530 に答える