c++

The best way I know to write readable regex in C and C++

The question is: http://stackoverflow.com/questions/3978351/how-to-avoid-backslash-escape-when-writing-regular-expression-in-c-c Stackoverflow does not allow to answer my own question. So I post it as a faked "question" When I reading [C: A reference manual] Chapter 3: Prepressors. An idea emerges: #define STR(a) #a #define R(var, r...

C++ STL vector reserve

I have tested on stl vector with code below: struct structA{ char charArray[256]; } structA a; ..assign 256 characters to a.charArray vector<structA> v1; v1.reserve(1000); for(int i=0; i<1000; i++){ v1.push_back(a); } I realized that for every 16 push_back, there is a spike in the v1.push_back. I suspect that there is a reall...

Explaining why dual purpose classes are bad

I have a class in a system that lists its purpose as "This can either be seconds-from midnight. Or a time with a date." I have tried to explian how bad this is but I cant get my point accross. Do anyone have any ideas on how to tackle this. http://code-slim-jim.blogspot.com/2010/10/object-anti-patterns.html ...

Most Common Mistake done/seen in C++

Possible Duplicate: What C++ pitfalls should I avoid ? What is the most common mistake in C/C++programming that you keep committing or see most of the people do? Being aware of it atleast subconsciously will increase my or anyone's chances of committing it. ...

GlutSolidSphere not solid

Hi my program is supposed to display a solid red colored sphere in the center of the screen, all i am getting is the boundary of the sphere : int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA); glutInitWindowSize(800,600); glutInitWindowPosition(0,0); glutCreateWindow("Sphere")...

What is the differnce between "const X a" and "X const a" if X is the class

i have a class name X, what is the difference between "const X a" and "X const a" ...

C++ database communication library

Hello, I'm looking for a well designed, efficient and robust C++ cross-database and cross-platform database communication library. I need support for Oracle MySQL PostgreSQL Firebird (optional) MSSQL (optional) When I say cross-platform I really mean cross-platform, I need something similar to boost. Currently I'm researching soci,...

How Utility functions can be shared across various classes ?

Hi, I had a class Display with 2 utility functions getDate and getTime like below. class Display { public: void getDate(char *pDate); //Utility functions for converting to custom format void getTime(char *pTime); }; Later, In other class called Retriever also, i needed the same Utility functions getDate and getTime. I do not want ...

How to avoid if cond. for stack operation

Hello All, I have created a stack class which holds std::vector. I have written stack operation like pop() and exch() like int Stack::pop() { if (v.size() < 0) throw("Error : Stack Underflow"); int tos = v.back(); stack.erase(v.end()-1); return tos; } void Stack::exch() // Exchange top 2 element { if (v.size() < 2) ...

Qt QComboBox with different background color for each item?

Greetings all, Is there a way to set a different background color for each item in a QComboBox ? Thank in advance ...

Outlining in VS2008, C++, not working

I'm using VS2008 (version 9.0.30729.1 SP) and have found that outlining regularly stops working. I get outlining options for the start and end of functions, and for comment blocks, but not for other code blocks, such as ifs, while loops, for loops, etc... Using Reset all settings, as recommended in a similar previous question temporari...

Recursive read of TCollection

Hi, I'm very bad with recursion, never used it before. I know the theory of it .. not that that helps :)) For my problem i have a structure of TCollection that contains TCollection and TCollectionItem etc .. I have to write a recursion function that will read all my TCollectionItems. Here is graphical view: TCollection->TCollectionItem...

sizeof() problems with empty class inheritance

#include <stdio.h> class X { }; class Y { // long x; // case A) // X x; // case B) }; class Z : public Y, public X { }; int main() { Z z; printf("%d %d %d\n", sizeof(Z), sizeof(Y), (char*)static_cast<X*>(&z) - (char*)&z); return 0; } Why is the output as follows after uncommenting either case ...

Pimpl not working.

This is a very noobish mistake, but I dont know whats happening here. There are loads of pimpl examples but I dont understand why this isn't working (this was one of the examples more or less but I dont see the difference). I have a very simple Pimpl example, but it wont work. // Foo.hpp #include <boost/scoped_ptr.hpp> class Foo { s...

how to use boost::unordered_map

hello, for my application, i need to use a hash map, so i have written a test program in which i store some instances of a baseclass in a boost::unordered_map. but i want to reach the instances by calling special functions which return a derived class of the base and i use those functions' parameters for hash key of unordered_map. if no...

How a main function is being called in a c/cpp project.

Good day good-looking computer people, I might be asking a bit too much, but here it goes. I'm trying to do a bit of reserve engineering on this sound library. Looking at the main.cpp file (which I have posted below) it has two methods, setup and play. I'm a bit confused as to how this is working: When you run the Xcode project, shou...

32 Bit Com Server on 64 Bit System

Hi, i developed a Com Server and on windows XP 32 bit. To Test the Com Server i created a Client with C# to call the Functions via Interop. Everything works fine, but now i need to get the ComServer run on a Windows 7 64 bit System. I took the ComServer DLL and the C# EXE to the 64 bit Computer, registered the ComServer DLL with regsrv32...

Get the path "difference" between two directories

The situation: I got one or more absolute paths, e.g.: /home/benjamin/test/ /home/benjamin/test/a/1 /home/benjamin/test/b/1 How can I get the difference between two paths? Let's say I want to know how I can get from path 1 to path 2. Expected result would be /home/benjamin/test/a/1 - /home/benjamin/test/ = /a/1 Is there a more ele...

MFC Treeview : How to check if Treeview already contain particular child node ?

Hi, In MFC Treeview control, how i can check condition if particular child node is already present in treeview? My requirement is like if particular child node is present in treeview dont add it again in that treeview... Any code snippet is welcome ........ Thanks. ...

slot machine payout calculation

I want to create a 5 reels slot machine calculation system and I'm not sure what approach to take. I understand that there is a lot of math within it, especially if I want the machine to be enjoyable to a player. Are there any tips/links for that? Was looking for info at the web but they discuss on it from the player's perspective rath...