Having trouble with this program complex.h

  • #1
Hey, I'm having trouble with this program

This is the code:

#include <complex>
#include <iostream>

using namespace std;
using std::complex;

int main ()
{
complex <double> c1; // complex numbers with double components
complex <double> c2;
cout << "Type in a complex number: ";
cin >> c1;
c1 *= 2;
cout << "|c1*2| = " << cabs(c1) << endl;
cin.get();
cin.get();
return 0;
}

however it doesn't seem to recognize any of the complex functions.. I don't know why... ? I get this error

14 C:\Dev-Cpp\main23.cpp no matching function for call to `cabs(std::complex<double>&)'
 

Answers and Replies

  • #2
79
0
FrostScYthe said:
14 C:\Dev-Cpp\main23.cpp no matching function for call to `cabs(std::complex<double>&)'
Couple thoughts:
You give a windows style path, are you using MS Visual C++?
1. Is cabs in namespace std? Try "std::cabs(...".
2. Why use cabs? Why not use std::abs?
3. MSVC++ doc lists _cabs, not cabs. Is cabs/_cabs standard, portable, etc? Not sure, but the abs provided via <complex> looks standard in C++.

Cheers,
Tim
 
Last edited:
  • #3
jim mcnamara
Mentor
4,062
2,521
MSVC++ is not ISO compliant. So you might want to plunge into your mdsn for visual studio distribtuion that comes with MSVC++ and try a look at "complex"
 
  • #4
Hurkyl
Staff Emeritus
Science Advisor
Gold Member
14,916
19
complex.h and complex are unrelated. The C99 and C++ complex libraries are disjoint. cabs is the C99 function. C++ simply overloads the abs function.

In other words, you wanted to use abs.


P.S. if you've already issued a using namespace std command, it is redundant to issue a using std::complex command.
 
Last edited:

Related Threads on Having trouble with this program complex.h

Replies
2
Views
2K
  • Last Post
2
Replies
31
Views
3K
Replies
1
Views
2K
  • Last Post
Replies
2
Views
2K
Replies
16
Views
2K
Replies
4
Views
682
Replies
1
Views
3K
Replies
5
Views
3K
Replies
1
Views
2K
Replies
3
Views
667
Top