?

T

tequila

errors:
Complex.cpp:27: error: no matching function for call to
'Complex::Complex()'
Complex.cpp:11: note: candidates are: Complex::Complex(double, double)
Complex.cpp:9: note: Complex::Complex(const Complex&)

Complex.cpp:48: error: no matching function for call to
'Quaternion::Quaternion(Complex&)'
Complex.cpp:27: note: candidates are: Quaternion::Quaternion(double,
double, double, double)
Complex.cpp:44: note: Quaternion::Quaternion(const
Quaternion&)

can someone please help?

#include <iostream>

using std::cin;
using std::cout;
using std::endl;
using std::string;

class Complex {
public:
Complex(double m,double n) { r = m; i = n; }
virtual void add(Complex w) { r += w.r; i += w.i; }
string myinfo() {
return "I am a complex "; }
double getr() {
return r; }
double geti() {
return i; }

private:
double r,i;
};

class Quaternion : public Complex {
typedef Complex super;
public:
Quaternion(double m,double n,double o, double p) {
Complex(m,n); j = o; k = p; }
void add(Quaternion x) { super::add(x);
j += x.j; k += x.k; }
string myinfo(){
return "I am a quaternion " + super::myinfo()+ " "; }
double getk() {
return k; }

private:
double j,k;
};

int main() {
Complex z = Complex(1.0,1.0);
cout << z.myinfo() <<endl;
Complex w = Complex(1.0,1.0);
Quaternion q = Quaternion(1.2,3.4,5.6,7.8);
z = q;
z.add(w);
cout << z.myinfo() << endl;
q.add((Quaternion) z);
cout << q.myinfo() << endl;
}
 
T

Tobias Blomkvist

tequila sade:
Quaternion(double m,double n,double o, double p) {
Complex(m,n); j = o; k = p; }

I suppose you want to call the base class constructor instead
of creating a temporary object, especially since a constructor
without any parameters doesn't exist, as the error indicates.

Quaternion(double m,double n,double o, double p) : Complex(m,n)
{
j = o; k = p;
}

Tobias
 
S

Sensei

class Quaternion : public Complex {
typedef Complex super;
Useless.

public:
Quaternion(double m,double n,double o, double p) {
Complex(m,n); j = o; k = p; }

What the hell... how's going to handle the complex? Where is stored? Do
you know somebody has to write a little variable holding the complex
number?
void add(Quaternion x) { super::add(x);
j += x.j; k += x.k; }

Here you call complex, but you have NO instance of it.

string myinfo(){
return "I am a quaternion " + super::myinfo()+ " "; }
double getk() {
return k; }

private:
double j,k;
};

Add some variable. If quaternion has to deal with complex, like complex
has the internal double, quaternion must have internal complex
variables.

You'd better buy a book on basics...
 
V

Victor Bazarov

Sensei said:

No, it's not. It could be a common typedef for several classes, and
just like any other member of 'Quaternion', it is its _interface_.
What the hell... how's going to handle the complex? Where is stored?
Do you know somebody has to write a little variable holding the
complex number?

Apparently the idea is to invoke the base class' constructor. See
Tobias' reply for the correction.
Here you call complex, but you have NO instance of it.

'this' points to the _instance_of_it_.
string myinfo(){

Add some variable. If quaternion has to deal with complex, like
complex has the internal double, quaternion must have internal complex
variables.

It has it: the base class subobject.
You'd better buy a book on basics...

Perhaps you should do the same...

V
 
M

Matthias Kaeppler

Sensei said:
What the hell... how's going to handle the complex? Where is stored? Do
you know somebody has to write a little variable holding the complex
number?

Yes, and this variable is *this.
Though his code is ill-formed, the call to the base class constructor
would be perfectly fine; it will initialize the base class part of
Quaternion, that is, those attributes specific to Complex.
Here you call complex, but you have NO instance of it.

Bogus. Learn the language properly before trying to give advise.
Class instances only store state information, that is, the values
of its attributes at a given time. Since Quaternion is also a Complex,
calling super::add on *this is perfectly fine.
You'd better buy a book on basics...

Uh, yeah...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top