初期化リストを使用した単純なコンストラクタ?
-
22-09-2019 - |
質問
私は私の時間ファイルを含めましたし、私の問題は、コンパイラが初期化子リストと私のシンプルな例外クラスのコンストラクタのが好きされていないということです以下。また、私は時間ファイルの先頭にstring is undeclared identifier
を持っているにもかかわらず、その#include <string>
を言っています。あなたは私が間違ってやっている何かを参照していますか?さらに説明については、これは私がWindows上でwxWidgetsのGUIアプリケーションに統合するよというのが私のドメインクラスの1つです。
ありがとうございます。
TIME.H
#pragma once
#include <string>
#include <iostream>
// global constants for use in calculation
const int HOURS_TO_MINUTES = 60;
const int MINUTES_TO_HOURS = 100;
class Time
{
public:
// default Time class constructor
// initializes all vars to default values
Time(void);
// ComputeEndTime computes the new delivery end time
// params - none
// preconditions - vars will be error-free
// postconditions - the correct end time will be returned as an int
// returns an int
int ComputeEndTime();
// GetStartTime is the getter for var startTime
// params - none
// returns an int
int GetStartTime() { return startTime; }
// GetEndTime is the getter for var endTime
// params - none
// returns an int
int GetEndTime() { return endTime; }
// GetTimeDiff is the getter for var timeDifference
// params - none
// returns a double
double GetTimeDiff() { return timeDifference; }
// SetStartTime is the setter for var startTime
// params - an int
// returns void
void SetStartTime(int s) { startTime = s; }
// SetEndTime is the setter for var endTime
// params - an int
// returns void
void SetEndTime(int e) { endTime = e; }
// SetTimeDiff is the setter for var timeDifference
// params - a double
// returns void
void SetTimeDiff(double t) { timeDifference = t; }
// destructor for Time class
~Time(void);
private:
int startTime;
int endTime;
double timeDifference;
};
class HourOutOfRangeException
{
public:
// param constructor
// initializes message to passed paramater
// preconditions - param will be a string
// postconditions - message will be initialized
// params a string
// no return type
HourOutOfRangeException(string pMessage) : message(pMessage) {}
// GetMessage is getter for var message
// params none
// preconditions - none
// postconditions - none
// returns string
string GetMessage() { return message; }
// destructor
~HourOutOfRangeException() {}
private:
string message;
};
class MinuteOutOfRangeException
{
public:
// param constructor
// initializes message to passed paramater
// preconditions - param will be a string
// postconditions - message will be initialized
// params a string
// no return type
MinuteOutOfRangeException(string pMessage) : message(pMessage) {}
// GetMessage is getter for var message
// params none
// preconditions - none
// postconditions - none
// returns string
string GetMessage() { return message; }
// destructor
~MinuteOutOfRangeException() {}
private:
string message;
};
class PercentageOutOfRangeException
{
public:
// param constructor
// initializes message to passed paramater
// preconditions - param will be a string
// postconditions - message will be initialized
// params a string
// no return type
PercentageOutOfRangeException(string pMessage) : message(pMessage) {}
// GetMessage is getter for var message
// params none
// preconditions - none
// postconditions - none
// returns string
string GetMessage() { return message; }
// destructor
~PercentageOutOfRangeException() {}
private:
string message;
};
class StartEndException
{
public:
// param constructor
// initializes message to passed paramater
// preconditions - param will be a string
// postconditions - message will be initialized
// params a string
// no return type
StartEndException(string pMessage) : message(pMessage) {}
// GetMessage is getter for var message
// params none
// preconditions - none
// postconditions - none
// returns string
string GetMessage() { return message; }
// destructor
~StartEndException() {}
private:
string message;
};
解決
あなたはそれを修飾する必要があるので、
string
は、名前空間std
である:std::string
。初期化子リストは問題とは何の関係もありません。
は無関係な注記で、あなたの例外クラスがstd::runtime_error
のように、標準ライブラリの例外のいずれかから派生することを検討することがあります。
所属していません StackOverflow