0

オブジェクトを作成して.hファイル内のコードを実行しようとしています。何が間違っていますか?

    //TicketFineCalculator.h
#include <iostream>
using namespace std;

class TicketFineCalculator
{

    public:
int getFine() {
        int procFee, zone, speedLimit, actualSpeed, totalFine;
     int anotherRun = 1;
     while (anotherRun == 1){
cout << "\n-------------------------------";
cout << "\nSpeeding Ticket Fine Calculator";
cout << "\n-------------------------------";
cout << "\nEnter processing fee, in dollars:";
cin >> procFee;
cout << "\nSpeeding Ticket #1";
cout << "\nEnter the type of speeding offense (1 for regular, 2 for work zone, 3 for residential district):";
cin >> zone;

cout << "\nEnter the speed limit, in miles per hour:";
cin >>  speedLimit;
cout << "\nEnter the vehicle's speed, in miles per hour:";
cin >> actualSpeed;
cout << "\nThe total fine is:" << totalFine;
cout << "\nEnter 1 to enter process another speeding ticket or 0 to quit:";
cin >> anotherRun;
     } // terminates while loop
return totalFine; 
        }
 // Calculate the total fine given the road zone, speed limit, and the vehicle's actual speed.
 // Return the fine as an integer.

};


//Project1.cpp
#include <iostream>
#include "TicketFineCalculator.h"

int totalFine;
TicketFineCalculator::getFine(totalFine);

    int main(){
    cout << totalFine;
return 0;
} //terminates main
4

1 に答える 1

1

TicketFineCalculator内でgetFine()メソッドを呼び出す場合は、次のようにメソッドを静的に宣言する必要があります。

class TicketFineCalculator
{
public:
    static getFine()
    {
    }
};

または、TicketFineCalculatorのインスタンスを作成し、そのインスタンスを使用してメソッドを呼び出す必要があります。

于 2012-04-09T04:18:16.913 に答える