PDA

View Full Version : C++ problem under MAC. Please help!




forfan
Nov 23, 2007, 12:21 AM
I am not sure whether it is a MAC problem or not.
I am new to mac programming.

Recently I am trying to learn program with MTL4(http://www.osl.iu.edu/research/mtl/mtl4/doc/manual.php3).

Here is a sample program copied from MTL document. It is a very simple program which implements a complex vector and prints it out by using MTL.

// File: vector2.cpp
#include <complex>
#include <iostream>
#include <boost/numeric/mtl/mtl.hpp>

int main(int argc, char* argv[])
{
using namespace mtl;
// Define dense vector of complex with 7 elements.
dense_vector<std::complex<float>, vector::parameters<tag::row_major> > v(7);

// Set all elements to 3+2i
v= std::complex<float>(3.0, 2.0);
std::cout << "v is " << v << "\n";

// Set all elements to 5+0i
v= 5.0;
std::cout << "v is " << v << "\n";

v= 6;
std::cout << "v is " << v << "\n";

return 0;
}


I tried to compile it under terminal, and got the following error:

$ g++ -I/usr/Local/MTL4 -I/usr/local/boost_1_34_1 Vector2.cpp -o Vector2 -lm -O2
Vector2.cpp: In function ‘int main(int, char**)’:
Vector2.cpp:15: error: incompatible types in assignment of ‘std::complex<float>’ to ‘mtl::vector::dense_vector<std::complex<float>, mtl::vector::parameters<mtl::tag::row_major, mtl::vector::non_fixed::dimension, false, false> > [7]’
Vector2.cpp:19: error: incompatible types in assignment of ‘double’ to ‘mtl::vector::dense_vector<std::complex<float>, mtl::vector::parameters<mtl::tag::row_major, mtl::vector::non_fixed::dimension, false, false> > [7]’
Vector2.cpp:22: error: incompatible types in assignment of ‘int’ to ‘mtl::vector::dense_vector<std::complex<float>, mtl::vector::parameters<mtl::tag::row_major, mtl::vector::non_fixed::dimension, false, false> > [7]’


why the compiler can't do a auto conversion for me?

My OS is Leopard,
g++ version:
i686-apple-darwin9-g++-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465)

any advise?

thx in advance.



ethernet76
Nov 23, 2007, 12:25 AM
any advise?

thx in advance.

Man back in the day when i programmed, int main passed no arguments.
It actually looks like you're assigning values incorrectly. As all your errors are on assignment lines.

ethernet76
Nov 23, 2007, 12:31 AM
It also helps to try and describe what the code is trying to do.

forfan
Nov 23, 2007, 12:38 AM
I have tested the program under my linux box, and got same error messages.

It is not a Mac programming problem, but I still need help.
Can anybody help for that?

forfan
Nov 23, 2007, 12:45 AM
the program uses MTL to construct a complex vector with size 7.

v = n means assigning n to every element of vector.

I know it is an assignment error.

The problem is why it fails. I thank MTL vector class should have a good assignment implementation.

maybe there is something wrong with my compile command.

I have totally no idea with the error.

ethernet76
Nov 23, 2007, 12:49 AM
I don't think you need the extra > when you create your dense vector. It has no opening < which means it's probably treating it as a conditional statement.

forfan
Nov 23, 2007, 12:56 AM
this line?
dense_vector<std::complex<float>, vector::parameters<tag::row_major> > v(7);

there are 3 "<" and three ">", one for dense_vector, one for complex and one for vector::parameters.
I don't think it is a problem.

I tried to remove the last > and got a "lose > " error.
I don't think you need the extra > when you create your dense vector. It has no opening < which means it's probably treating it as a conditional statement.

forfan
Nov 23, 2007, 01:24 AM
I made a stupid spelling error in code input:
dense_vector<std::complex<float>, vector::parameters<tag::row_major> > v(7);
I input the code "v[7]" but not "v(7)".
:)
Very stupid.

Sorry for that.