Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

forfan

macrumors newbie
Original poster
Nov 20, 2007
5
0
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.
Code:
// 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.
 

forfan

macrumors newbie
Original poster
Nov 20, 2007
5
0
Sorry, it is not the right place to post my question

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

macrumors newbie
Original poster
Nov 20, 2007
5
0
Thank you for the replies

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

macrumors 6502a
Jul 15, 2003
501
0
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

macrumors newbie
Original poster
Nov 20, 2007
5
0
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

macrumors newbie
Original poster
Nov 20, 2007
5
0
problem solved

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.