473,473 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

[STL] Segmentation fault on using std::sort

Hello

I am new to template programming, so i tried the 'example' from
http://www.sgi.com/tech/stl/functors.html.
I can compile the code but when i want to run the program
I get a segmentation fault when the part of std::sort(...) is
reached, but I don't understand why.
------------ Code start ---------------------

#include <iostream>
#include <vector>

struct less : public std::binary_function<double, double, bool> {
bool operator()(double x, double y) { return x < y; }
};

int main(){
std::vector<double> V(50);

std::generate(V.begin(), V.end(), rand);

std::sort(V.begin(), V.end(), less());
}

--------------- Code end -----------------------

thanks in advance

Manfred

PS: I am using linux and gcc 3.4.4 but this shouldn't be the problem
afaik
Jul 23 '05 #1
8 4207


Manfred wrote:
Hello

I am new to template programming, so i tried the 'example' from
http://www.sgi.com/tech/stl/functors.html.
I can compile the code but when i want to run the program
I get a segmentation fault when the part of std::sort(...) is
reached, but I don't understand why.

[snip]

PS: I am using linux and gcc 3.4.4 but this shouldn't be the problem
afaik


i just tried running your program and it runs fine! i use gcc 3.3.4

Jul 23 '05 #2
Manfred <ne******@web.de> wrote:
I can compile the code but when i want to run the program
I get a segmentation fault when the part of std::sort(...) is
reached, but I don't understand why.

#include <iostream>
#include <vector>

struct less : public std::binary_function<double, double, bool> {
bool operator()(double x, double y) { return x < y; }
};

int main(){
std::vector<double> V(50);
std::generate(V.begin(), V.end,rand
std::sort(V.begin(), V.end,less
}

I doubt that this code compiles. You're missing some parentheses after
function and method/constructor calls. After adding them everything should
work fine. Maybe you can post the actual (compiling) code you're using.

Martin
Jul 23 '05 #3
Martin Gieseking wrote:
Manfred <ne******@web.de> wrote:

I can compile the code but when i want to run the program
I get a segmentation fault when the part of std::sort(...) is
reached, but I don't understand why.

#include <iostream>
#include <vector>

struct less : public std::binary_function<double, double, bool> {
bool operator()(double x, double y) { return x < y; }
};

int main(){
std::vector<double> V(50);
std::generate(V.begin(), V.end,rand
std::sort(V.begin(), V.end,less
}


I doubt that this code compiles. You're missing some parentheses after
function and method/constructor calls. After adding them everything should
work fine. Maybe you can post the actual (compiling) code you're using.


Huh?!

Your newsreader must have screwed up what i posted.
But here once again:

------------ Code start ---------------------

#include <iostream>
#include <vector>

struct less : public std::binary_function<double, double, bool> {
bool operator()(double x, double y) { return x < y; }
};

int main(){
std::vector<double> V(50);

std::generate(V.begin(), V.end(), rand);

std::sort(V.begin(), V.end(), less());
}
--------------- Code end -----------------------

Manfred
Jul 23 '05 #4
forayer wrote:

Manfred wrote:
Hello

I am new to template programming, so i tried the 'example' from
http://www.sgi.com/tech/stl/functors.html.
I can compile the code but when i want to run the program
I get a segmentation fault when the part of std::sort(...) is
reached, but I don't understand why.

[snip]

PS: I am using linux and gcc 3.4.4 but this shouldn't be the problem
afaik

i just tried running your program and it runs fine! i use gcc 3.3.4


Thanks I tried gcc 3.3.4 and it works :)
Strange thing. Maybe my gcc or libstdc++ is damaged. :(

Manfred
Jul 23 '05 #5


Manfred wrote:
[snip]
Thanks I tried gcc 3.3.4 and it works :)
Strange thing. Maybe my gcc or libstdc++ is damaged. :(


the latest stl files can be downloaded from sgi. do a 'gcc -v' to check
where gcc looks for the c++ includes.

cheers,
forayer

Jul 23 '05 #6
forayer wrote:
the latest stl files can be downloaded from sgi. do a 'gcc -v' to check
where gcc looks for the c++ includes.

cheers,
forayer


I have the newest g++ includes, because i built gcc 3.4.4 and 3.3.4 from
sources. I'll ask for it in the forums of my distro.

Thanks anyway

Manfred
Jul 23 '05 #7
Martin Gieseking <mg******@uos.de> wrote:
Manfred <ne******@web.de> wrote:
I can compile the code but when i want to run the program
I get a segmentation fault when the part of std::sort(...) is
reached, but I don't understand why.

#include <iostream>
#include <vector>

struct less : public std::binary_function<double, double, bool> {
bool operator()(double x, double y) { return x < y; }
};

int main(){
std::vector<double> V(50);
std::generate(V.begin(), V.end,rand
std::sort(V.begin(), V.end,less
}


I doubt that this code compiles. You're missing some parentheses after
function and method/constructor calls. After adding them everything should
work fine. Maybe you can post the actual (compiling) code you're using.


Are you using an older version of ZoneAlarm, by chance?

See <http://tinyurl.com/8axvj>.
Jul 23 '05 #8
Thomas Edison <fo*@bar.invalid> wrote:
Are you using an older version of ZoneAlarm, by chance?

See <http://tinyurl.com/8axvj>.


By the way, the new Google Groups seems to be FUBAR (at least on here) --
so the messages in that thread keep repeating and repeating and
repeating...
Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Aaron Broad | last post by:
I can't get STL sort to work for this little huffman encoding program i'm writing. I get a whole whack of errors eminating from the line that call sthe sort. They all look like the following...
10
by: Paul Schneider | last post by:
I want to sort a class derived from std::vector with STL sort.: template<typename T, typename fitParaType, typename fitResType> class Manipulator{ // shouldn't I now be able to access private...
6
by: Der Andere | last post by:
I have an array of pointers (to a class) which I want to have sorted. I have implemented the < operator for the class but I guess STL sort will sort the pointers according to _their_ values (the...
7
by: Stuart | last post by:
The stl::sort() that comes with Dev Studio 6 is broken (it hits the degenerate case in a common situation). I have a replacement. I would like to globally do "using namespace std; except use my...
7
by: yinglcs | last post by:
Hi, I have a function which calls stl sort(). I pass in a STL list of 'Rect' (my own class), like this: void sortListY(const list<Rect>& rectList) { sort(rectList.begin(),...
1
by: Varun Kacholia | last post by:
Hi, I have a question regarding SGI STL sort implementation: In case of equal elements, will they be output in the same order each time I sort? (I understand that it is not a stable sort, and by...
8
by: markww | last post by:
Hi, If I have a vector of structs like this: struct IMAGE { unsigned char *pPix; string strName; int nNumber; };
11
by: Magcialking | last post by:
I wanna sort a pointer vector with the algorithm "sort" in STL like this: " int compare(vector<string*>::iterator a,vector<string*>::iterator b){ return (**a)<(**b); } ...
5
by: feverzsj | last post by:
STL sort() as an implementation of introsort, below is the code snippet from the gnu stl. template<typename _RandomAccessIterator, typename _Size> void __introsort_loop(_RandomAccessIterator...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.