By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,110 Members | 1,553 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,110 IT Pros & Developers. It's quick & easy.

question on valarray

P: n/a
Just a few lines:

1: valarray<int> t(0, 10);
2: for (int i = 0; i < 10; ++i)
3: t[i] = 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.
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Tue, 20 Jan 2004 23:34:11 +0800, "Milan" <so*****@internet.com>
wrote:
Just a few lines:

1: valarray<int> t(0, 10);
valarray<int> t(10); //since you initialize below
2: for (int i = 0; i < 10; ++i)
3: t[i] = 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
Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.