c++

C++ virtual function not called in subclass

Hi, Consider this simple situation: A.h class A { public: virtual void a() = 0; }; B.h #include <iostream> class B { public: virtual void b() {std::cout << "b()." << std::endl;}; }; C.h #include "A.h" #include "B.h" class C : public B, public A { public: void a() {std::cout << "a() in C." << std::endl;}; }; in...

Inconsistent operator new/delete calling

I'm having some trouble with a dynamically linked library calling my overloaded operator delete but not my operator new. My exe looks something like this: class A { public: void func() { t = dynLib::Type::CreateObject(); } dynLib::Type t; }; void main() { A a; a.func(); } And then I have a statically linke...

Windows: How do I calculate the time it takes a c/c++ application to run?

I am doing a performance comparison test. I want to record the run time for my c++ test application and compare it under different circumstances. The two cases to be compare are: 1) a file system driver is installed and active and 2) also when that same file system driver is not installed and active. A series of tests will be conducted ...

How to code Const and Mutable overloads?

I seem to have this pattern occuring pretty often in my code, with two functions performing the same task apart from the constness of their parameters/returns. int& myClass::getData() { return data; } // called for const objects const int& myData::getData() const { return data; } This offends my sense of DRY. It's no...

Drawing in C++ using Visual Studio 2005

Hello I have a problem with drawing in C++ using Visual Studio 2005. After event handling on MouseMove the results of using DrawLine function appear in PictureBox but if some window overlap the part of PictureBox all pixels in this place dissapear after moving the window. How can I solve this problem? ...

Header Guards and LNK4006

Hi, I have a character array defined in a header //header.h const char* temp[] = {"JeffSter"}; The header if #defined guarded and has a #pragma once at the top. If this header is included in multiple places, I get an LNK4006 - char const * * temp already defined in blahblah.obj. So, I have a couple of questions about this Why does...

Has anyone seen this improvement to quicksort before?

Handling repeated elements in previous quicksorts I have found a way to handle repeated elements more efficiently in quicksort and would like to know if anyone has seen this done before. This method greatly reduces the overhead involved in checking for repeated elements which improves performance both with and without repeated elements....

Trying to use/include/compile 3rd party library, libmagic. C/C++ filetype detection

After looking for a way to detect the filetype of a file stream, I found that the Unix file command uses libmagic and I'm trying to make use of the library myself, but I can't get it to work. I've rarely integrated 3rd party code in my own, so that's probably a big part of my problem as well. Why: I'm doing this because I have a portab...

How to fix 'expected primary-expression before' error in C++ template code?

Here's yet another VC9 vs. GCC 4.2 compile error problem. The following code compiles fine with VC9 (Microsoft Visual C++ 2008 SP1) but not with GCC 4.2 on Mac: struct C { template< typename T > static bool big() { return sizeof( T ) > 8; } }; template< typename X > struct UseBig { static bool test() { return X...

Favorite C++ template hack

Templates are both the blessing and curse of C++. Someone hates them, someone loves them. For those of you are in the latter group, whats your favorite template "hack", and what does it do? I'll start with my personal favorite, the "friender". This template allowes access to protected members - which I very frequently use for unittestin...

How would one setup autotools to build a project for separate architectures, concurrently, on multiple systems?

I've got a C++ project which uses automake and autoconf. I'm new to both of these. My home directory is network mounted -- the same on every server we have -- and I want to compile and run the project (and its executable) concurrently on separate machines. Our servers are frequently different architectures. My desktop is 32-bit, but th...

Starting wxWidgets C++ need a gentle nudge

So I've been learning C# for like a year now (I'm 20 years old) and I'm getting pretty confident with it. I've also been meddling with C++ every now and again. For example just recently I've been following the Nehe OpenGL tutorials for C++ and I find it a fun way of learning. I want to start looking at creating cross platform GUI softwa...

quickly invalidate cache

Is there a way in c++ to quickly invalidate the L2 cache of a processor other than iterating through a large fake array? ...

When are C++ destructors explicitly called?

What are the instances where you need to explicitly call a destructor? ...

Basic Game DrawEngine question

Hi, i want to create a basic game Draw engine class for my 2D game. i'm not quite sure whether to share main window handle with class or keep it private as it is in the main class. The other way i'm thinking to do is pass the device context itself to draw engine class. which would be the standard way to work with draw engine? ...

Problems initializing glut

I have simplified my problem to this example: #include <GL/glut.h> int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (600, 600); glutInitWindowPosition( 0, 0 ); int win = glutCreateWindow("Recon"); return 0; } When it execu...

C++ Disabling warnings on a specific include

Hi, I'm wondering if there's a way to disable all warnings on a specific file (for example, using a preprocessor directive). I'm using CImg.h and I want to get rid of the warnings involving that code. I'm compiling both with VS (the version for Windows) and gcc (the Linux one), so I would like to have a generic way... Thanks! ...

Open source libraries for abstracting database access in C++?

I'm looking for options for abstracting database server details away from my application (in c++), I'd like to write my code to be independent of the actual database backend. I know MySQL has a nice library, but I don't want to be tied to a single database implementation. Are there good options for this? ...

Getting Original Regular Expression Out From sregex (Boost Xpressive)

I have the following code. sregex rex = sregex::compile( "(\\w+) (\\w+)!" ); How I can get "(\w+) (\w+)!" out from rex? ...

Simple Programming Theory Question

Hi guys does anyone know why the programming language C++ is used more widely in biometric security applications compared to the programming language Java? The answers that I have collected so far are 1) Virtual Compilers 2) OpenCV Library provided by C++. Can anyone help with this question?? ...