From: Pat on 2 Dec 2009 12:46 I wanted to text the use of complex numbers in C++, so I set up the following (very simple) program: ************************************** #include <iostream> #include <complex.h> using namespace std; int main() { complex z; z = complex(1,2); cout << "z=" ,z,<< endl; return 0; } ************************************** However, when I compile this I get the following errors: error: missing template arguments before "z" error: expected ";" before "z" This code is almost identical to some other examples I've come across, and it seems consistent with how other data types are defined, so I'm not sure what is wrong. Any ideas? Thanks, Pat
From: Francis Glassborow on 2 Dec 2009 13:04 Pat wrote: > I wanted to text the use of complex numbers in C++, so I set up the > following (very simple) program: > > ************************************** > #include <iostream> > #include <complex.h> standard headers do not have .h > > using namespace std; > > int main() > { > complex z; > z = complex(1,2); > cout << "z=" ,z,<< endl; look at the above line which I am pretty sure was the one flagged by your compiler. What are those commas doing?
From: Keith Thompson on 2 Dec 2009 13:08 Pat <pkelecy@_REMOVETHIS_gmail.com> writes: > I wanted to text the use of complex numbers in C++, so I set up the > following (very simple) program: > > ************************************** > #include <iostream> > #include <complex.h> Drop the ".h". > using namespace std; > > int main() > { > complex z; > z = complex(1,2); > cout << "z=" ,z,<< endl; > > return 0; > } > ************************************** > > However, when I compile this I get the following errors: > > error: missing template arguments before "z" > error: expected ";" before "z" This should tell you that you're missing some template arguments. complex is a class template, not a class. The type you want is probably complex<double>, not complex. And you don't want the commas in the cout line; use "<<", not ",". -- Keith Thompson (The_Other_Keith) kst-u(a)mib.org <http://www.ghoti.net/~kst> Nokia "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"
From: Pat on 2 Dec 2009 13:24 Francis Glassborow wrote: > Pat wrote: >> I wanted to text the use of complex numbers in C++, so I set up the >> following (very simple) program: >> >> ************************************** >> #include <iostream> >> #include <complex.h> > > standard headers do not have .h >> >> using namespace std; >> >> int main() >> { >> complex z; >> z = complex(1,2); >> cout << "z=" ,z,<< endl; > look at the above line which I am pretty sure was the one flagged by > your compiler. What are those commas doing? Opps! Those commas are a typo. They shouldn't be there. With regard to header, the example I was basing this on actually had the ".h". But even with that removed, and with everything past the "complex z;" commented out, I'm still getting these errors. So the error is specially related to the "complex z;" declaration. Any other ideas? Thanks, Pat
From: Pat on 2 Dec 2009 15:35 Keith Thompson wrote: > Pat <pkelecy@_REMOVETHIS_gmail.com> writes: >> I wanted to text the use of complex numbers in C++, so I set up the >> following (very simple) program: >> >> ************************************** >> #include <iostream> >> #include <complex.h> > > Drop the ".h". > >> using namespace std; >> >> int main() >> { >> complex z; >> z = complex(1,2); >> cout << "z=" ,z,<< endl; >> >> return 0; >> } >> ************************************** >> >> However, when I compile this I get the following errors: >> >> error: missing template arguments before "z" >> error: expected ";" before "z" > > This should tell you that you're missing some template arguments. > > complex is a class template, not a class. The type you want is > probably complex<double>, not complex. > > And you don't want the commas in the cout line; use "<<", not ",". > Yes, you were right. I needed complex<double>. The example I was referring to had a "typedef complex<double> comp;" at the top, which I had missed. So with that corrected it's now working as expected. Thanks for the help. Pat
|
Next
|
Last
Pages: 1 2 Prev: Define overloaded operators for structures? Next: Compile and write C++ code on a Netbook? |