私が抱えている問題は、文字列パラメーターにあります。使い方がよくわかりません。ユーザーが入力するまで、分類の長さが未定義の文字列を持つようにしたいだけです。私が得ているエラーは、文字列分類を入力すると、「std::string classification」の宣言がパラメーターをシャドウすることです。文字列引数をクラス メンバーに渡す正しい方法は何ですか?
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
class Shapes
{ //Begin Class Definition
private:
float side;
float height;
int exponent;
string *classification;
public:
Shapes(float side, float height, string * classification);
//CONSTRUCTOR
~Shapes(){};
//DESTRUCTOR
float area(float side, float height, string *classification);
float perimeter(float side, float height, string *classification);
}; // End Class Definition
int power(float side, int exponent)
{
int i;
int total[exponent];
float sum;
for ( i = 0 ; i < exponent ; i ++ )
{
total[i]= side;
sum *= total[i] ;
}
return sum;
}
float Shapes::area(float side, float height, string *classification)
{
float area=0.0;
string classification;
getline(cin,string);
if (classification == "square" )
{
area = power(side,2);
return area;
}
if (classification == "triangle" )
{
area = (side* height) / 2 ;
return area;
}
if (classification == "hexagon" )
{
float constant = 2.598706;
area= constant * power(side,2);
return area;
}
if (classification == "circle" )
{
}
};