2013-11-28 5 views
2

현재 과제를 프로그래밍 중이며 대부분 C++을 처음 사용합니다. 함수를 사용하기 전에 함수를 정의해야하거나 .cpp 파일에서 함수를 사용하기 전에 헤더 파일을 사용하여 함수를 프로토 타입 화해야합니다.식별자 "customerMenu"가 정의되지 않았습니다.

그러나 이들 중 하나를 수행하면 여전히 메서드가 정의되지 않는다는 오류가 발생합니다.

이 내 지저분한 헤더 파일입니다 ... 여기

#ifndef DRIVER_H 
#define DRIVER_H 
#include "Account.h" 
#include <vector> 
#include <iostream> 
#pragma once 

using namespace std; 

class Driver { 

private: 

public: 
void prevAccount(vector<Customer> customers); 
void nextAccount(vector<Customer> customers); 
void accountActions(vector<Customer> customers); 
void listCustomerAccounts(vector<Customer> customers); 
void selectAccount(vector<Customer> customers); 
void createAccount(vector<Customer> customers); 
void prevCustomer(vector<Customer> customers); 
void nextCustomer(vector<Customer> customers); 
void customerActions(vector<Customer> customers); 
void listCustomers(vector<Customer> customers); 
void selectCustomer(vector<Customer> customers); 
void createCustomer(vector<Customer> customers); 
void customerMenu(vector<Customer> customers); 
void main(); 
}; 

#endif 

그리고는 ...

#include "Account.h" 
#include "Customer.h" 
#include "Driver.h" 
#include "JuniorCurrentAccount.h" 
#include "CorporateSavingsAccount.h" 
#include "StudentSavingsAccount.h" 
#include "CurrentAccount.h" 
#include "Transaction.h" 
#include <stdlib.h> 
#include <iostream> 
#include <string> 
#include <vector> 
using namespace std; 

static int customerIndex = 0; 
static int accountIndex = 0; 
static int accNum = 1; 


//tier 5 
void Driver::accountActions(vector<Customer> customers) { //code } 
void Driver::prevAccount(vector<Customer> customers) { //code } 

//tier 4 
void Driver::createAccount(vector<Customer> customers) { //code } 
void Driver::selectAccount(vector<Customer> customers) { //code } 
void Driver::listCustomerAccounts(vector<Customer> customers) { //code } 

//tier 3 
void Driver::customerActions(vector<Customer> customers) { //code } 
void Driver::nextCustomer(vector<Customer> customers) { //code } 
void Driver::prevCustomer(vector<Customer> customers) { //code } 

// tier 2 
void Driver::createCustomer(vector<Customer> customers) { //code } 
void Driver::selectCustomer(vector<Customer> customers) { //code } 
void Driver::listCustomers(vector<Customer> customers) { //code } 

//tier 1 
void Driver::customerMenu(vector<Customer> customers) { //code } 

void main() 
{ 
vector<Customer> customers; 

cout << "________________________" << endl; 
cout << "//MAIN MENU " << endl; 
cout << "||Customers (1) " << endl;  
cout << "||"; 

int mainMenuChoice; 
cin >> mainMenuChoice; 

if (mainMenuChoice == 1) 
{ 
    customerMenu(customers); 
} 
} 

의 맨 아래 본질적으로 프로그램을 실행하는 드라이버의 .cpp 파일입니다 .cpp 파일은 오류에 대해 불평하는 곳입니다. 실제로이 오류가 나타나는 이유를 이해하지는 못합니다. 정의를 다뤘다 고 생각하기 때문입니다.

공간을 절약하기 위해 메소드 본문에서 코드를 가져 왔지만, 본질적으로 기능을 수행하거나 계층의 메소드를 더 많이 호출합니다 (1에서 2로 호출하고 3에서 2로 호출).

답변

3

오류 메시지의 텍스트를 게시 한 경우 도움이되지만 Driver라는 클래스에서 함수를 정의했지만 주 기능에 Driver 개체가없는 것 같습니다.

내가 내 주요 클래스로 Driver.cpp을 이해하는 것이다 컴파일러를 가정했던이

int main() 
{ 
    Driver driver; 
    vector<Customer> customers; 

    cout << "________________________" << endl; 
    cout << "//MAIN MENU " << endl; 
    cout << "||Customers (1) " << endl;  
    cout << "||"; 

    int mainMenuChoice; 
    cin >> mainMenuChoice; 

    if (mainMenuChoice == 1) 
    { 
     driver.customerMenu(customers); 
    } 
} 
+0

이것은 의미가 있습니다. 저는 Driver가 자동으로 기본 클래스로 간주되어 initialised 될 필요가 없다고 가정했습니다 (Java 에서처럼). 그러나 특별히 초기화 할 필요가 있는지는 몰랐습니다. 감사! – Azzah

2

함수 customerMenu은 독립 함수가 아니며 Driver 클래스의 멤버입니다. 당신이 필요한 이유, 당신이 몇 가지 기본적인 튜토리얼로 돌아가 할 수 있습니다 생각을 이해하지 않는 경우

Driver myDriver; 
myDriver.customerMenu(customers); 

: 그것은 당신이 당신의 함수를 호출하는 것이 먼저 Driver 개체 인스턴스를 필요 의미합니다. 추가 팁으로


: 기초 후에는 참조에 의해 인수를 전달하는 방법에 대해 학습 할 수 있습니다. 지금 당장 customers 벡터 을 값으로 전달하므로 각 함수 호출에 대해 복사됩니다. 또한 각 함수에 고유 한 사본이 있고 매개 변수로 전달 된 벡터가 아닌이 개인용 사본에 대한 수정이 수행됨을 의미합니다.

+0

시도하지만, 분명하지. 나는 기본적인 튜토리얼을 완성하지도 않았다. 자바에 관한 지식을 토대로이 프로그래밍을하고있다. 우리는 내가 할 수있는 일을하기 위해 막 끝까지 던져졌습니다. 그리고 참조와 포인터에 관해서는 먼저 기본 구현을 먼저 얻은 다음 그 것에 대해 제대로 배울 것입니다. 대답 주셔서 감사합니다, 지금 이해가 되네요! – Azzah

관련 문제