no matching function
Jan 3, 2019 at 11:22pm UTC
hello my friends i have ^roblem with my code i try Study of the mechanism of composition of objects
i have erore code "no matching function"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
main.cpp
#include <vector>
#include <windows.h>
#include <Complexe.h>
#include "Somme.h"
using namespace std;
int main()
{Somme s1();
cout<<s1.Sommedesnormes()<<endl;
}
////////////////////////
Complexe.h
#ifndef COMPLEXE_H
#define COMPLEXE_H
#include <iostream>
class Complexe
{
public :
Complexe(double re,double im,double no);
double norme();
private :
double re;
double im;
double no;
};
#endif
////////
Complexe.cpp
#include "Complexe.h"
#include <cmath>
Complexe::Complexe(double re,double im,double no)
{
this ->re=re;
this ->im=im;
this ->no=no;
}
double Complexe::norme()
{
no= std::sqrt(100);
return no;
}
///////////
Somme.h
#ifndef SOMME_H
#define SOMME_H
#include <Complexe.h>
#include <iostream>
class Somme
{
public :
Somme();
void Sommedesnormes();
private :
double s ;
Complexe c1 ;
Complexe c2 ;
};
#endif
/////////////////
Somme.cpp
#include "Somme.h"
#include "Complexe.h"
#include <Complexe.h>
#include <iostream>
Somme::Somme()
{
Complexe c1(1.0,-1.0,0.0);
Complexe c2(2.0,-1.0,0.0);
s=0.0;
};
void Somme::Sommedesnormes()
{
s=c1.norme()+c2.norme();
};
Jan 3, 2019 at 11:42pm UTC
Somme s1();
that's a function that takes no parameters and returns a `Somme' object
remove the parenthesis or use braces to create an object using the default constructor
Jan 4, 2019 at 7:44pm UTC
In addition to what
ne555 mentioned, you have some other problems.
Line 61: Sommedesnormes returns nothing (void). Line 13: You can't cout a void.
Line 65-66: you're declaring c1 and c2, but Complexe has no default constructor.
Note: You don;t need a default constructor if you initialize them as shown below.
Lines 72-73: Why are you including the header twice?
Lines 79-80: You're declaring local instances of c1 and c2. These go out of scope when the constructor exists.
Presumably you meant to initialize members c1 and c2.
77 78 79
Somme::Somme() : c1(1.0, -1.0, 0.0), c2(2.0, -1.0, 0.0)
{ s = 0.0;
}
Last edited on Jan 4, 2019 at 7:46pm UTC
Topic archived. No new replies allowed.