c++

Pthreads C/C++ compilation problem

Hello, I'm getting error "undefined reference to `pthread_attr_init'", even though that should be in pthread.h. This is in a UNIX environment that should be set up for Pthreads. Also, is a void* a good way to point to the current matrix? Here's my code, any ideas? #include <cstdlib> #include <iostream> #include <sstream> #include <strin...

what is the capacity of an empty vector?

Looks like a stupid question. But comment to my answer to one of the SO question made me to think again. [ comment says, capacity need not be zero for empty vector] By default my answer would be 0 as there are no elements inside vector. It makes sense to keep the capacity as 0 and on the first allocation it can be increased without an...

Sharing methods between two implementations of a virtual base class in C++

I have a virtual base class and two classes that implement the various methods. The two classes have the same functionality for one of the methods. Is there away I can share the implementation between the two classes to eliminate redundant code? I tried making the first class a parent of the second class in addition to the virtual base c...

Why do I see 64-bit pointers in C++ on my 32-bit Mac OS X system?

So I've read a lot of related posts on SO and elsewhere such as: http://stackoverflow.com/questions/399003/is-the-sizeofsome-pointer-always-equal-to-four It makes total sense to me that on a 32-bit system I would expect 4-byte pointers and on a 64-bit system I would expect 8-byte pointers. So I'm running this code: int main() { cou...

How to read data from file and display in QEditText box in QT

i would like to read a line of data from text file and display that data in Text Edit box ...

Sorting an std::map by a different key?

I'm trying to use STL to solve the following problem (I don't want to implement my own data structure if I don't have to). I've come up with a working implementation, but I'm hoping there's something faster...or is what code I have the best way to do it? I have a large data set in which each entry contains two items: a key and a size. ...

Crash when utilising a std:map

In my SDL program, I am using a map construct to simulate an "infinite" array of objects within a certain class. The code manages to compile fine, but when I run the program, as soon as one of the functions using the maps is trigger, the program crashes, returning a value of 3. So, here's exactly what I'm doing: class MyClass { pu...

Algorithm for vector problem

What would be the best algorithm for the undermentioned problem. Implement method PrintFamilyTree() that prints out the Name and Generation of the tree Output should resemble Name: Jan Generation:0 Name: Mike Generation:1 Name: Greg Generation:2 Name: Carol: Generation: 2 Name: Peter Generation: 3 Name: Marcia Generation: 3 Name: Bobby ...

Should the conditional operator evaluate all arguments?

When writing this: 1: inline double f( double arg ) { 2: return arg == 0.0 ? 0.0 : 1./arg; 3: } 4: const double d = f( 0.0 ); The microsoft visual studio 2005 64-bit compiler came with line 4: warning C4723: potential divide by 0 While you and I can clearly see that a div-by-zero is never going to happen... Or is it? ...

Seemingly basic C++ question

Alright, so this is annoying the hell out of me and I'm sure its a simple thing to do. Basically, I'm working with an open source C++ client called POCO to make a email client for a class... Basically, I have a pop3 client object that retrieves emails from my email server, and then puts the emails in an object called MailMessage. Now, I...

move c++ program to foreground

I used daemon() and fork() to move my program to the background. How can I bring it back to the foreground? Is there a c++ function that do so? thank you. edited: I understand that there is no way back from daemon() so how can I move my program from foreground to background and back? ...

Visual Studio fails to display some watched expressions

In Visual Studio, most of my objects and variables cannot be resolved during a debugging session for various reasons. This means I cannot inspect or watch objects or their invoke their functions making it extremely difficult to debug my code because most of my expressions simply won't work. Some typical errors I get when adding an expr...

how to create a 20000*20000 matrix in C++

I try to calculate a problem with 20000 points, so there is a distance matrix with 20000*20000 elements, how can I store this matrix in C++? I use Visual Studio 2008, on a computer with 4 GB of RAM. Any suggestion will be appreciated. ...

Sending message to different thread

Is there any API to send message to a thread? Basically I have only threadId available and I want to send a custom message to that thread. ...

not able to install hooks for all threads in a process

I am hooking keyboard in application . Requirement is to hook keyboard in all threads in the process. I used SetWindowsHookEx API SetWindowsHookEx(WH_KEYBOARD_LL, (HOOKPROC)::KeyboardHookProc, hInst, 0); The hook is created for all the threads in process. This works fine until calling thread exists .As soon as calling thread terminat...

How to debug a program that is terminating in an unhandled exception???

Hi all, I am programming in C++ on Linux platform. My program terminates with this (unhandled???) exception: "terminate called after throwing an instance of 'long'" Aborted The code that is throwing the exception is inside try-catch block, then why should this happen?? The exception is thrown while returning from a function. I am us...

How to find out if a thread has message queue?

Is there any way to find out from threadId , if a thread has message queue or not? Basically there are some windows api which only work if a thread has message queue.window ...

Can we use pthread instead of NSThread in iPhone apps

Well I have an application that uses both Objective C & c++ but for portability reasons I have tried to use c++ as much as possible.... Now I am confronted with some problem that requires threads I was thinking of using pthread instead of NSThread.... is it Okay to use pthread... will Apple punish me for using it by rejecting my app on t...

NULL pointer is the same as deallocating it?

I was working on a piece of code and I was attacked by a doubt: What happens to the memory allocated to a pointer if I assign NULL to that pointer? For instance: A = new MyClass(); {...do something in the meantime...} A = NULL; The space is still allocated, but there is no reference to it. Will that space be freed later on, will it...

C++ inheritance problem

Here are my classes: ParentClass, ParentObj DerivedClass (inherits from ParentClass), DerivedObj (inherits from ParentObj). ParentClass has a protected member: std::vector< ParentObj* > DerivedClass allocates only DerivedObj* objects to this vector. Problem is: When I use ParentClass, I want to access its vector object...