question on valarray

M

Milan

Just a few lines:

1: valarray<int> t(0, 10);
2: for (int i = 0; i < 10; ++i)
3: t = i;
4: valarray<int> t2 = t[slice(0, 3, 1)];

Line 4 causes a core dump with g++. Why?

Besides, if I change line 4 to the following:
valarray<int> t2 = (valarray<int>) t[slice(0, 3, 1)];
It works with Visual C++ but not with g++ (Compilation error. I forgot what
the message was). Is there any way to fix it?

Thanks.

Regards,
Milan.
 
T

tom_usenet

Just a few lines:

1: valarray<int> t(0, 10);

valarray said:
2: for (int i = 0; i < 10; ++i)
3: t = i;
4: valarray<int> t2 = t[slice(0, 3, 1)];

Line 4 causes a core dump with g++. Why?


Compiler bug? The code is fine, and works for me on GCC 3.2.
Besides, if I change line 4 to the following:
valarray<int> t2 = (valarray<int>) t[slice(0, 3, 1)];

You shouldn't use C-style casts in C++ usually. In any case, the cast
isn't necessary.
It works with Visual C++ but not with g++ (Compilation error. I forgot what
the message was). Is there any way to fix it?

Upgrade? What version are you using?

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top