c++

Static Class Variables in Dynamic Library and Main Program

I am working on a project that has a class 'A' that contains a static stl container class. This class is included in both my main program and a .so file. The class uses the default(implicit, not declared) constructor/destructor. The main program loads the .so file using dlopen() and in its destructor, calls dlclose(). The program cra...

C++ Profiling: KiFastSystemCallRet

I searched for this after seeing it's the top rated item when profiling using Very Sleepy, and it seems everyone gets the answer "it's a system function, ignore it". But Sleepy's hint for the function says: Hint: KiFastSystemCallRet often means the thread was waiting for something else to finish. Possible causes might be d...

how is push_back implemented in STL vector?

I was asked this question in an interview. The points I answered are like this 1) an index pointing to the current position; 2) resize if neccessary. Can anybody elaborate more? ...

Implementing implicitly shared classes outside of Qt

I'm familiar with the way Qt uses D-pointers for managing data. How do I do this in my code? I tried this method: 1) move all data into a struct 2) add a QAtomicInt to the struct 3) implement a = operator and change my constructor/deconstructor to check-up on the reference count. The issue is, when I go to do a shallow copy of the obj...

C++ using cdb_read returns extra characters on some reads

Hi All, I am using the following function to loop through a couple of open CDB hash tables. Sometimes the value for a given key is returned along with an additional character (specifically a CTRL-P (a DLE character/0x16/0o020)). I have checked the cdb key/value pairs with a couple of different utilities and none of them show any addit...

boost::binding that which is already bound

I have a Visual Studio 2008 C++ application that does something like this: template< typename Fcn > inline void Bar( Fcn fcn ) // line 84 { fcn(); }; template< typename Fcn > inline void Foo( Fcn fcn ) { // this works fine Bar( fcn ); // this fails to compile boost::bind( Bar, fcn )(); }; int main() { SYSTEM_...

gcc compilation without using system defined header locations

I am attempting to compile a c++ class using gcc. Due to the nature of the build, I need to invoke gcc from a non-standard location and include non-system defined headers, only to add a set from a different location. However, when I do this, I run into an issue where I cannot find some base symbols (suprise suprise). So i am basically ru...

How to build a sentence parser using only the c++ standared library?

Hello everyone, I am designing a text based game similar to Zork, and I would like it to able to parse a sentance and draw out keywords such TAKE, DROP ect. The thing is, I would like to do this all through the standard c++ library... I have heard of external libraries (such as flex/bison) that effectively accomplish this; however I don...

[MFC] What is the reciprocal of CComboBox.GetItemData?

Instead of associating objects with Combo Box items, I associate long ids representing choices. They come from a database, so it seems natural to do so anyway. Now, I persist the id and not the index of the user's selection, so that the choice is remembered across sessions. If id no longer exists in database - no big deal. The choice wil...

[C++] Initializing Primitive Array to One Value

Is there a way to initialize an array of primitives, say a integer array, to 0? Without using a for loop? Looking for concise code that doesn't involve a for loop. :) ...

C++ private pointer "leaking"?

I'm going to create a class to hold a long list of parameters that will be passed to a function. Let's use this shorter example: class ParamList{ public: ParamList(string& a_string); string& getString(); //returns my_string private: string& my_string; } My question is this: my_string is private, yet I'm returning the ref...

list of pointers in c++

What i want to do is for (list<cPacket *>::iterator i = cache.begin(); i != cache.end(); i++){ if( strcmp(i->getName(),id) == 0 ){ return true; } } where getName is function of the class cPacket, But it does not work, i tries also i.operator->()->getName(), and again nothing. Can anybody help me? ...

why pointer to pointer is needed to allocate memory in function

Hi I have a segmentation fault in the code below, but after I changed it to pointer to pointer, it is fine. Could anybody give me any reason? void memory(int * p, int size) { try { p = (int *) malloc(size*sizeof(int)); } catch( exception& e) { cout<<e.what()<<endl; } } it does not work in the main funct...

Why wont my while loop take new input (c++)

I've written a program to get a string input from a user and parse it into tokens and move a robot according to the input. My problem is trying to issue more than one command. The code looks like: void Navigator::manualDrive() { const int bufSize = 42; char uinput[bufSize]; char delim[] = " "; char *token; while(t...

not working function with no errors

hello.. I've implemented a function to display an avl tree after inserting nodes into it like this template<class nodetype> void AVLtree<nodetype>::display() const { display(Proot); } template<class nodetype> void AVLtree<nodetype>::display(Node<nodetype> * ptr) const { if(ptr==0) return ; cout<<ptr->value<<" "; display(ptr->Plef...

What color to use in owner-draw Windows List Control background?

I have an owner-drawn list control in my Windows program. I use CListCtrl::GetBkColor to get the background color, and for a selected item I use GetSysColor(COLOR_HIGHLIGHT). This matches what Windows uses for non owner drawn list controls, except for the case where the control doesn't have focus - then the background is replaced with gr...

set static member pointer variables

I'm trying to set a static pointer variable in a class but I'm getting these errors for each variable I try to set. error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2040: 'xscroll' : 'int' differs in levels of indirection from 'float *' error C2440: 'initializing' : cannot convert from '...

Running multiprocess applications from MATLAB

I've written a multitprocess application in VC++ and tried to execute it with command line arguments with the system command from MATLAB. It runs, but only on one core --- any suggestions? Update:In fact, it doesn't even see the second core. I used OpenMP and used omp_get_max_threads() and omp_get_thread_num() to check and omp_get_max_t...

Two main functions

Can we have two main() functions in a C++ program? ...

Is there a safe / standard way to manage unstructured memory in C++?

I'm building a toy VM that requires a block of memory for storing and accessing data elements of different types and of different sizes. I've done this by writing a wrapper class around a uint8_t* data block of the needed size. That class has some template methods to write / read typed data elements to / from arbitrary locations in the...