By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,127 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,127 IT Pros & Developers. It's quick & easy.

?

P: n/a
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;
}

Jul 27 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
--
IMPORTANT: The contents of this email and attachments are confidential
and may be subject to legal privilege and/or protected by copyright.
Copying or communicating any part of it to others is prohibited and may
be unlawful.
Jul 27 '05 #2

P: n/a
On 2005-07-27 17:31:08 -0500, "tequila" <te******@gmail.com> said:
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...

--
Sensei <se******@tin.it>

cd /pub
more beer

Jul 27 '05 #3

P: n/a
Sensei wrote:
On 2005-07-27 17:31:08 -0500, "tequila" <te******@gmail.com> said:
class Quaternion : public Complex {
typedef Complex super;
Useless.


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_.
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?


Apparently the idea is to invoke the base class' constructor. See
Tobias' reply for the correction.
void add(Quaternion x) { super::add(x);
j += x.j; k += x.k; }
Here you call complex, but you have NO instance of it.


'this' points to the _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.


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


Perhaps you should do the same...

V
Jul 28 '05 #4

P: n/a
Sensei wrote:
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?


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.
void add(Quaternion x) { super::add(x);
j += x.j; k += x.k; }

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...

--
Matthias Kaeppler
Jul 28 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.