c++

Changing terminalinterface command after showing it on qt/kdelibs app

I have this terminal on my qt/kde application KLibFactory* factory = KLibLoader::self()->factory("libkonsolepart"); KParts::Part* p = static_cast<KParts::Part*> (factory->create(this,"terminal",QStringList() << "terminal")); assert(p); TerminalInterface* terminalInterface= qobject_cast<TerminalInterface*> (p); terminalInterface->showShe...

Best way for interprocess communication in C++

I have two processes one will query other for data.There will be huge amount of queries in a limited time (10000 per second) and data (>100 mb) will be transferred per second.Type of data will be an integral type(double,int) My question is in which way to connect this process? Shared memory , message queue , lpc(Local Procedure call) o...

How to automatically sort a QTreeWidget column?

Hello, i'm using a QTreeWidget to display some simple items. I've set the list sortable by .setSortingEnabled(true) calling. In this way, the list is sorted only when the user press the title column, and not automatically whenever new item is inserted. I have two question: Is there a way to force the automatic sorting in a specified co...

c++ expected primary expression

I'm working on a very simple game (essentially an ice sliding puzzle), for now the whole things in one file and the only level is completely blank of any form of obstacle. It throws up a few errors. My current annoyance is an expected primary expression error, can anyone tell me how to fix it (it throws up at line 99)? Here's the whole ...

Populate a vector<int> from integers in a char *

char *values = " 3 1 4 15"; vector<int> array; I want to populate the array with the values, 3,1,4,15 Is there a slick way to do it with the stl copy algorithm? ...

How do I programmatically check memory use in a fairly portable way? (C/C++)

I'm writing cross platform C++ code (Windows, Mac). Is there a way to check how much memory is in use by the current process? A very contrived snippet to illustrate: unsigned long m0 = GetMemoryInUse(); char *p = new char[ random_number ]; unsigned long m1 = GetMemoryInUse(); printf( "%d bytes used\n", (m1-m0) ); Of course (m1-m0) sho...

Why is "array" a reserved word in C/C++?

Visual Studio syntax highlighting colors this word blue as if it were a keyword or reserved word. I tried searching online for it but the word "array" throws the search off, I get mostly pages explaining what an array is. What is it used for? ...

C++ Instance Initialization Syntax

Given a class like this: class Foo { public: Foo(int); Foo(const Foo&); Foo& operator=(int); private: // ... }; Are these two lines exactly equivalent, or is there a subtle difference between them? Foo f(42); Foo f = 42; Edit: I confused matters by making the Foo constructor "explicit" in the original question...

Is there a standard C++ function object for taking apart a std::pair?

Does anyone know if there's a de-facto standard (i.e., TR1 or Boost) C++ function object for accessing the elements of a std::pair? Twice in the past 24 hours I've wished I had something like the keys function for Perl hashes. For example, it would be nice to run std::transform on a std::map object and dump all the keys (or values) to ...

Get/Set in the c++ world, faux-pas?

I notice that get/set is not the c++ way as far as I can tell by looking at boost/stl, and even reading the writings of some of the top c++ experts. Does anyone use get/set in their c++ class design, and can someone suggest a rule of thumb on where if at all this paradigm belongs in the c++ world? It is obviously very popular in Java, ...

Problem with a constructor c++

So I have this code for these Constructors of the Weapon class: Weapon(const WeaponsDB * wepDB); Weapon(const WeaponsDB * wepDB_, int * weaponlist); ~Weapon(void); And I keep getting an error: 1>c:\users\owner\desktop\bosconian\code\bosconian\weapon.h(20) : error C2062: type 'int' unexpected and ensuing errors (more than listed): ...

C++ programming style

Hi guys, I'm an old(but not too old) Java programmer, that decided to learn C++. But I have seen that much of C++ programming style, is... well, just damn ugly! All that stuff of putting the class definition in a header file, and the methods in a different source file; Calling functions out of nowhere, instead of using methods inside cl...

MFC Edit Box - Multiple Characters per Keystroke?

I am trying to create a simple dialog in MFC using Visual C++. My problem is that when I get the dialog on the screen and try to type in an Edit Box field, if I type the letter 'a' once, it appears in the edit box as 'aaaaaaaaaaa' (that's 12 a's). Furthermore, if I try to navigate around in the box using the arrow keys, the carat moves...

What techniques can be used to speed up C++ compilation times?

What techniques can be used to speed up C++ compilation times? This question came up in some comments on this question: http://stackoverflow.com/questions/372862/c-programming-style And I'm interested to hear what ideas there are. I've seen this related question, but that doesn't provide many solutions: http://stackoverflow.com/questi...

Help with C++ List erase function

I'm trying to do a simple erase and keep getting errors. Here is the snippet of code for my erase: std::list<Mine*>::iterator iterMines = mines.begin(); for(int i = oldSizeOfMines; i >0 ; i--, iterMines++) { if(player->distanceFrom(*iterMines) < radiusOfOnScreen) { onScreen.push_back(*iterMines); iterMines = onScreen.erase(iterMi...

Do people still live by the 80 column rule?

I have recently been converted, at least on the principal that I can read and edit my code as I left it from any terminal in the world. But I still ask myself, when will I ever need to do that? I am finding in c++, especially modern c++, my lines are longer, with more namespace qualified references, etc. So what do people think, 80 colu...

Need a good unmanaged C++ OCX example

I need a very simple and clear example of how to create an OCX in unmanaged C++ code. Ideally, I'd like to consume it in Office, but any container (i.e. VB6, .NET WinForms) should be good. I am having trouble seeing how I can add controls to the OCX canvas... I have seen examples of opening dialogs from within the OCX's load event... bu...

Beginner C++ Question - Unresolved external symbols!

Don't be too hard on me! Simply put: foo.h: #include "bar.h" class foo { private: bar it; void DoIt(); } bar.h: class bar { public: void Test(); } foo.cpp: void foo::DoIt() { it.Test(); } This will result in a: error LNK2001: unresolved external symbol Why? ...

Why does stdafx.h work the way it does?

Hi all.. As usual, when my brain's messing with something I can't figure out myself, I come to you guys for help :) This time I've been wondering why stdafx.h works the way it does? To my understanding it does 2 things: Includes standard headers which we might (?) use and which are rarely changed Work as a compiler-bookmark for when ...

Destructor not called when type-casted void pointer to object

Sample void func(void* data) { CResource* resource = (CResource*)data; delete resource; // ~CResource never called. resource = NULL; } Kindly help me to figure out this. ...