c++

What tools must a C++ programmer be familiar with when programming in industry rather than recreationally?

I'm interested in the differences in work flow, code management, tools you might be expected to be familiar with etc. Not stuff like "your code will need more rigorous testing", or "your code will need to be more readable/maintainable" or "getting paid"! These are obvious I think. Also, I don't really want a list of the pros and cons ...

compiling libmagic statically (c/c++ file type detection)

Thanks to the guys that helped me with my previous question. (linked just for reference) I can place the files fileTypeTest.cpp, libmagic.a, and magic in a directory, and I can compile with g++ -lmagic fileTypeTest.cpp fileTypeTest. Later, I'll be testing to see if it runs in Windows compiled with MinGW. I'm planning on using libmagic ...

redefine a non-virtual function in C++

Hi, When I read Effective C++, it says, never redefine a non-virtual function in C++. However, when I tested it, the code below compiles correctly. So what's the point? It's a mistake or just a bad practice? class A { public: void f() { cout<<"a.f()"<<endl;}; }; class B: public A { public: void f() { cout<<"b.f(...

static binding of default parameter

In Effective C++, the book just mentioned one sentence why default parameters are static bound: If default parameter values were dynamically bound, compilers would have to come up with a way to determine the appropriate default values for parameters of virtual functions at runtime, which would be slower and more complicated than the cur...

Are there c++ classes or functions to use for asynchronous sockets between Unix and Windows?

Does someone please tell us where to find classes or functions that communicate with asynchronous sockets (TCP and UDP) between programs runing on unix and windows? Thanks for your reply PS; I have already programs that communicate with synchronous sockets. ...

Global variables in C++

I am supposed to write a program that should read from input numbers in the main() part, and then make some calculations in other bool functions. I don't want to insert the whole arrays of the numbers and all the other parameters in the functions everytime i call them. My question is this: Can i make somehow in c++ to read input in som...

cant exchange widget in QSplitter (Qt)

I have a QSplitter with two widgets. One of them is static, the other one is supposed to change on the press of a button. But the problem is the widget does not change? I have a pointer for the widget that is changing - this->content The widget to switch to is in the pointer named widget. Here's a code snippet where I switch the widge...

Design choice for sound effects

I'm trying to decide how I want to implement sound effects in my program. I've debating between 2 options. 1) Create an abstract interface SoundEffect and have every sound effect derive from that. Each sound effect is its own class. Upon construction, it opens the sound file and plays, and upon destruction it closes the file. The main d...

Can I make this C++ code faster without making it much more complex?

Hi all, here's a problem I've solved from a programming problem website(codechef.com in case anyone doesn't want to see this solution before trying themselves). This solved the problem in about 5.43 seconds with the test data, others have solved this same problem with the same test data in 0.14 seconds but with much more complex code. ...

Generic Alpha Beta Search with C++

I'm trying to design a function template which searches for the best move for any game - of course the user of this function template has to implement some game specific functions. What i'm trying to do is to generalize the alpha beta search algorithm with a function template. The declaration of this function template looks like this: ...

Linker errors even though I prevent them with #ifndef

I am getting linker errors that suggest I am not using #ifndef and #define. 1>TGALoader.obj : error LNK2005: "struct TGA tga" (?tga@@3UTGA@@A) already defined in main.obj 1>TGALoader.obj : error LNK2005: "struct TGAHeader tgaheader" (?tgaheader@@3UTGAHeader@@A) already defined in main.obj 1>TGALoader.obj : error LNK2005...

get heap corruption when changing member variables order

Hi all, i have a quite strange problem. my class has -among others- following memers: GLboolean has_alpha; GLuint width; GLuint height; GLuint length; GLuint millisPerFrame; GLfloat uv[2]; GLuint texsize[2]; GLint compsize; // location2 long preload_interval_next; long preload_interval; if i put the has_alpha at (location2) i g...

Invalid ESP when using multiple inheritance in C++ (VS2005)

I've been making a game which uses the Box2D physics engine, and I've come across some weirdness with the stack pointer (ESP) and multiple inheritance. I've managed to reproduce it in a minimal amount of code, and it seems that the order in which I declare the classes to be used in multiple inheritance seems to dictate whether the progra...

c++: Dynamically choose which subclass to create

Hello, I am new to c++ and i have a question. Lets say we have a base class Base and two derived classes, Derived1 and Derived2. f.e. Derived1 has a constructor taking a integer and Derived2 a constructor taking a boolean. Is it possible to determine at run time (or at compile time) which of those two subclasses to create and assign i...

Use of unique on STL vector with a structure

In a programming task, I'm trying to ensure a particular vector contains only unique items. With primitive types, the operation is as simple as: vector<int> lala; lala.push_back(1); lala.push_back(99); lala.push_back(3); lala.push_back(99); sort(lala.begin(), lala.end()); // lala: 1, 3, 99, 99 lala.erase(unique(lala.begin(), lala.end()...

setting QHeaderView background image

Im trying to set background-image for QHeaderView through a stylesheet. background-color works fine, but background-image does not. I've used the same stylesheet on another widget and it works. But wont work on QHeaderView... My stylesheet is: QHeaderView::section, QHeaderView { background-image:url(:/topgradient.png); backgroun...

Must -read articles for C++ memory mangement

After reading "C++ Memory Management: From Fear to Triumph" series, I think they are must-read articles for memory management. I'd like to know what else must-read articles I shouldn't miss. Thanks! ...

How do game events work?

I'v always wondered how this works. Does having more slow down the game? for example how would one represent checking if a car has flipped. It could be seen as: if (player.car.angle.y == 180) { do something } The parts that puzzle me is, when would the game check for it? The way I see it, every thing that can happen in the game seems...

c++ overloaded method in derived class

Hello! I have the following question: Assume base class A with method: A& operator+(A& a) {...} I also have a derived class B which overloads (or at least it should so) this method: A& operator+(B& b) {...} The problem is that if i want to call something like: b + a (where b is of type B and a of type A) i get a compile error. (e...

How can I recognize the last iteration in a C++ while loop?

How would I make so that the last player name doesn't have a , so it's: Player online: Jim, John, Tony and not Player online: Jim, John, Tony, My code is: bool Commands::whoIsOnline(Creature* c, const std::string &cmd, const std::string &param) { Player* player = dynamic_cast<Player*>(c); if (player) { player->sendTextMessage...