class Complex
{
public:
Complex(float = 0.0, float = 0.0); //default constructor that uses default arg. in case no init. are in main
void getComplex(); //get real and imaginary numbers from keyboard
void sum(Complex, Complex); //method to add two complex numbers together
void diff(Complex, Complex); //method to find the difference of two complex numbers
void prod(Complex, Complex); //method to find the product of two complex numbers
void square(Complex, Complex); //method to change each complex number to its square
void printComplex(); //print sum, diff, prod, square and "a+bi" form
private:
float real; //float data member for real number (to be entered in by user)
float imaginary; //float data member for imaginary number (to be entered in by user)
};
void Complex::getComplex()
{
cout << "Enter real number: ";
cin >> real;
cout << "Enter imaginary number: ";
cin >> imaginary;
}
void Complex::sum(Complex, Complex)
{
float sum = 0.0;
sum = real + imaginary;
}
int main()
{
Complex c;
c.getComplex();
c.sum(Complex, Complex);
c.diff(Complex, Complex);
c.prod(Complex, Complex);
c.square(Complex, Complex);
c.printComplex();
return 0;
}
Я получаю сообщение об ошибке при c.sum(Complex, Complex);
внутри основной (наряду с c.diff
, c.prod
и c.square
линий). Ошибка:имя Тип не допускается, (нельзя использовать перегрузку)
type name Complex is not allowed
и too few arguments in function call
Я не разрешается использовать перегружать операторы вообще для выполнения этой задачи. Что мне делать, чтобы разрешить это? Код сокращен, чтобы показывать соответствующие части. Еще раз спасибо.
Купите [вводную книгу] (http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) на C++. Перестаньте задавать такие основные вопросы. Кажется, вы не хотите прикладывать усилия, чтобы ПРОЧИТАТЬ книгу сначала, вместо этого вы хотите изучить C++, задав здесь вопросы. Это не то, как люди учатся. Вы задаете вопросы, когда у вас есть сомнения, прилагая усилия для чтения книг и статей. – Nawaz
'c.sum (Complex, Complex);' => 'c.sum (c, c);' Не имеет смысла, но должно исправить сообщение об ошибке. –
Прости, что обидел тебя @ Наваз. – Mang0Marquez