2013-03-13 2 views
0

아래 코드는 현재 작업하고있는 코드의 일부입니다. 나머지는 내 문제와 관련이 없습니다. 정보 combineInfo (정보 a1) 멤버 함수에 문제가 있습니다. 이 범위에서 선언이 아니라고 오류. 내가 원하는 모든 정보를 결합하여 새로운 변수를 설정됩니다. 나는 성공적 구조를 사용하여이 할 수 있었다 지금은 자기 학습 클래스입니다.C++ 멤버 함수 선언 문제

#include <iostream> 
#include <string> 

using namespace std; 

struct Date 
{ 
    int month; 
    int day; 
    int year; 
}; 

class Information 
{ 
public: 
    Information(); 
    void printinformation(); 
    Information combineInfo(Information a1); 
    //Setters and Getters Here 
private: 
    string a; 
    double b; 
    double c; 
    Date d; 
    Date e; 
}; 

void initializeDate(Date& d); 
void printDate(Date& d); 

int main() 
{ 
    cout << endl << "Now please input Information #1" << endl; 
    Information a1; // prompts for all the inputs for a1 
    cout << endl << "Now please input Information #2" << endl; 
    Information a2; // prompts for all the inputs for a2 
    a2.combineInfo(a1); // again prompts for info?? 
    cout << "The combined Information is: " << endl; 
    info.printinformation(); 
    return 0; 
} 

Information::Information() 
{ 
    string a; 
    cout << "Please enter a"<<endl; 
    getline(cin, a); 
    cout <<"Please enter b?"<<endl; 
    cin >> b; 
    getline(cin, dummy); 
    cout <<"Please enter c?"<<endl; 
    cin >> c; 
    getline(cin, dummy); 
    cout << "Please input the info start dates."<< endl; 
    initializeDate(start); 
    cout << "Please input the info end dates."<< endl; 
    initializeDate(finish); 
} 

Information Information::combineInfo(Information a1) 
{ 
    Information a1; 
    Information a2; 
    Information info; 
    a1.a = a2.a; 
    //etc. 
    return info; 
} 

답변

0

당신 가지고있다 :

a2.:combineInfo(a1); 

다음과 같아야합니다.

a2.combineInfo(a1); 

실수로 ':'이 추가로 있습니다.

+0

죄송합니다, 오타 -하지만 근본 문제가 해결되지 않습니다. –

1

코드는 컴파일 오류를 많이 제공하지만, 이상한 부분은 여기에 있습니다 :

Information a2; 
    a2.:combineInfo(a1); 
// ^^ Remove the : 

    cout << "The combined Information is: " << endl; 
    info.printinformation(); 
// ^^^^ 
// You didn't declare info 
+0

'main'에서'information a2'를 할 때, 들어가는 모든 정보를 묻습니다. 그런 다음 a2.combineInfo (a1)를 실행하면 다시 몇 가지 정보를 묻습니다. 왜 그리고 그렇게해서는 안되는지 확신 할 수 없습니다. 그것은 내 끝에서 잘 컴파일, 아마 내가 중요하다고 생각했던 것을 추출 할 때 중요한 부분을 놓친 것 같습니다. –

+0

@ user2163231 : 일부 정보를 묻는 코드는'Information' 클래스의 생성자에 있습니다. 나는 당신이 거기에 쓴 내용을 알고 있다고 생각했습니다. –

+0

정보 a1과 정보 a2를 실행하고 생성자를 통해 정보를 묻는 메시지가 표시됩니다. 그런 다음 a2.combineInfo (a1)를 실행하면 다시 몇 가지 정보를 결합하고 일부 변수를 동일하게 설정하는 대신 몇 가지 정보를 묻습니다. 이유가 확실하지 않습니다. –