2012-03-18 4 views
0

을 받고 있지만, 스피 점점 오류 :클래스에 대한 쓰기 기능을 만들려고 노력하고 내 클래스에 대한 쓰기 기능을 구현 한 오류

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을 사용합니다. 나는 전에는 보지 못했지만 여전히 같은 오류가 발생했다. – Zohaib

+0

어떤 인수 ur가 – Zohaib

+0

@ Zohaib에 대해 이야기하고 있습니다. 업데이트를 참조하십시오. – perreal

관련 문제