2012-03-18 3 views
0

を取得しますが、IAM取得エラー:クラスの書き込み機能をしようと、私は私のクラスの書き込み機能を実装したエラー

class Fa{ 
private: 
    string Q_; 
    string F_; 

public: 
    void write(ostream& out = cout) const{ 
    out<<Q_<<endl; 
    out<<F_<<endl; 
    } 
}; 

Error:default argument given for parameter 1 of `void Fa::write(std::ostream&) const'

は、誰もがこのエラーはどういう意味を教えてくださいすることができ、およびどうすればそれを避けることができますか?あなたが不足している

答えて

0

は含まれており、名前空間:

#include <iostream> 
#include <string> 

class Fa{ 
    private: 
    std::string Q_; 
    std::string F_; 

    public: 
    void write(std::ostream& out = std::cout) const{ 
     out << Q_<< std::endl; 
     out << F_<< std::endl; 
    } 
}; 

あなたは、ヘッダーとcppのファイルを持っている場合は、ヘッダファイルにデフォルト引数を指定:

/* ... */ 
    public: 
    void write(std::ostream& out = std::cout) const; 
    /* ... */ 

とCPPファイルで行いますがない:

void Fa::write(std::ostream& out) const { 
     /* ... */ 
    } 
+0

私はstd :: stringを使って追加しました。 std :: ostreamを使用しています。 std :: coutを使用します。 std :: endlを使用します。私はこれまでになかったが、私はまだ同じエラーを受けている。私はuがi'amは、このエラーが発生して言ったことなかったとして – Zohaib

+0

について – Zohaib

+0

@Zohaibを話してウルた引数、更新 – perreal

関連する問題