2015-01-29 9 views
-1

내 C++ 파일을 컴파일하는 데 문제가 있습니다. 이 오류가 내가 얻을 수 있습니다 :암시 적으로 선언 된 함수 오류 C++

여러 마커를이 줄 에서 - 회원 선언 를 찾을 수 없습니다 - 암시 적 선언 'InsultGenerator :: InsultGenerator (const를 InsultGenerator &)'내가는 MinGW을 사용하고

을 정의 내 컴파일러로.

다음
#include <iostream> 
#include <fstream> 
#include <string> 
#include <vector> 
#include "Insultgenerator_0hl14.h" 

using namespace std; 

FileException::FileException(const string& m) : message(m){} 

string& FileException::what(){ return message;} 

NumInsultsOutOfBounds::NumInsultsOutOfBounds(const string& m) : message(m){} 

string& NumInsultsOutOfBounds::what(){ return message;} 

InsultGenerator::InsultGenerator(const InsultGenerator&) {} 

void InsultGenerator::initialize() const{ 
int cols(0); 
string x; 

string filename("InsultsSource.txt"); 
ifstream file(filename.c_str()); 

if(file.fail()){ 
    throw FileException("File not read."); 
} 
while(file >> x){ 

}} 

//vector<string> InsultGenerator::talkToMe() const{ 

    // };//end talkToMe 

    // vector<string> InsultGenerator::generate(const int n) const{ 

    // };//end generate 

//int InsultGenerator::generateAndSave(const string filename, const int n)   const{ 

//};//end generateAndSave 

헤더 파일입니다 :

#ifndef INSULTGENERATOR_0HL14_H_ 
#define INSULTGENERATOR_0HL14_H_ 

#include <string> 
#include <vector> 

using namespace std; 

class InsultGenerator{ 
public: 
InsultGenerator(vector<string>); 
void initialize() const; 
string talkToMe() const; 
vector<string> generate(const int) const; 
int generateAndSave (const string, const int) const; 

private: 
vector<string> colA; 
vector<string> colB; 
vector<string> colC; 
}; 

class FileException{ 
public: 
FileException(const string&); 
string& what(); 
private: 
string message; 
}; 

class NumInsultsOutOfBounds{ 
public: 
NumInsultsOutOfBounds(const string &); 
string& what(); 
private: 
string message; 
}; 

#endif 
+3

당신이 전체 오류 텍스트를 제공 할 수 있을까요? 회원 선언을 찾을 수 없습니다 \t - - – horns

+0

여기가 \t이 줄에 여러 개의 마커 당신이 오류를보고하기 전에 당신이 만든 마지막 변경이 무엇인지 암시 적 선언 'InsultGenerator :: InsultGenerator (const를 InsultGenerator &)' –

+0

의 정의? 이것이 [오류를 생성하는 가장 간단한 코드인가?] (http://stackoverflow.com/help/mcve)? – Beta

답변

4

당신이 그것을 선언하지 않은하지만 당신은 InsultGenerator의 복사 생성자를 구현

다음은 C++ 코드입니다.

InsultGenerator 클래스에 InsultGenerator(const InsultGenerator&);을 추가하십시오. 과 같이 :

class InsultGenerator 
{ 
public: 
    InsultGenerator(vector<string>); // also better remove that one since I don't 
            // think you have implemented it 

    InsultGenerator(const InsultGenerator &); // here 
    void initialize() const; 
    string talkToMe() const; 
    vector<string> generate(const int) const; 
    int generateAndSave (const string, const int) const; 
private: 
    vector<string> colA; 
    vector<string> colB; 
    vector<string> colC; 
}; 
+0

어떻게 선언합니까? 죄송합니다, 나는 C++에 대해 잘 알고 있지 않습니다. –

+0

여전히 InsultGenerator가 필요합니다 (); 건설자? –

+0

@harmanlitt'벡터 '객체로 구성한다면, 그렇다. 지금은 생성자가 선언되었지만 정의되지 않았거나 사용되지 않았습니다. 클래스 밖에서 클래스를 정의하기 전에 멤버 함수를 선언하면됩니다. – Potatoswatter

0

편집 :

class InsultGenerator 
    { 
    public: 
     InsultGenerator(vector<string>); // Remove this line. 
     InsultGenerator(const InsultGenerator &); // Add this line. 
     void initialize() const; 
     string talkToMe() const; 
    ...... 
    } 
관련 문제