error: expected primary-expression before ‘double’

15,636

You seem to have written the function's declaration instead of calling it. Assuming you actually have a function called abs, you can call it by simply passing a variable to it in it's brackets:

cout << "Magnitude " << abs(c1) << endl;
Share:
15,636

Related videos on Youtube

Vildic M
Author by

Vildic M

Updated on June 04, 2022

Comments

  • Vildic M
    Vildic M almost 2 years
    #include <iostream> 
    #include <complex>
    
    using namespace std;
    
    class MyComplex{
      private:
        int real, img;
    
      public:
        MyComplex();
        MyComplex(int,int);
        ~MyComplex();
        void set(int,int);
        void display();
    };
    
    MyComplex::MyComplex(){
      cout << "i'm being constructed (default).\n";
      real=img=0;
    }
    
    MyComplex::MyComplex(int r, int i){
      cout << "i'm being constructed (parameterized).\n";
      real=r;
      img=i;
    }
    
    MyComplex::~MyComplex(){
      cout << "I'm being destroyed\n";
    }
    
    void MyComplex::set(int r, int i){
      real=r;
      img=i;
    }
    
    void MyComplex::display(){
      cout << real << "+i" << img << endl;
    }
    
    
    
    int main(){
      MyComplex c1;
      MyComplex c2(10,-8);
      c1.set(2,9);
      c1.display();
      c2.display();
    
      cout << "Magnitude"<< double abs(const complex) << endl;
    }
    

    First time in these forums, I apologize if my code is horribly written, I am but a beginner.

    I found an assignment on a book the requires you to calculate the magnitude of the complex numbers.

    I am getting this error:

    testcomplex.cpp: In function ‘int main()’:
    testcomplex.cpp:50:25: ***error: expected primary-expression before ‘double’
       cout << "Magnitude"<< double abs(const complex) << endl;***
    
    • rcs
      rcs about 9 years
      have you tried changing it to abs(complex)?
    • Biffen
      Biffen about 9 years
      What is a double doing there anyway?!
    • John Zwinck
      John Zwinck about 9 years
      double abs(const complex) makes no sense at all. What is it trying to do?
    • juanchopanza
      juanchopanza about 9 years
      You are trying to print a function declaration. That doesn't make much sense.