c++

Elegant way for a recursive C++ template to do something different with the leaf class?

I have a C++ class template that makes an Array of pointers. This also gets typedefed to make Arrays of Arrays and so on: typedef Array<Elem> ElemArray; typedef Array<ElemArray> ElemArrayArray; typedef Array<ElemArrayArray> ElemArrayArrayArray; I would like to be able to set one leaf node from another by copying the poi...

Issues passing values to shader

I am having issues passing values to my shader. My application compiles fine, but my cube object won't shade. Below is majority of my code. Most of my code for communicating with my shader is in createObject method myGame.cpp #include "MyGame.h" #include "OneColorCube.h" /* This code sets a projection and shows a turning cube. What ha...

Detect aborted connection during ASIO request

Is there an established way to determine whether the other end of a TCP connection is closed in the asio framework without sending any data? Using Boost.asio for a server process, if the client times out or otherwise disconnects before the server has responded to a request, the server doesn't find this out until it has finished the requ...

How to build boost foreach cycle

Hi guys! I have some abstract class called IClass (has pure virtual function). There are some classes which inherit IClass: CFirst, CSecond. I want to add objects of classes which inherit into boost::ptr_vector: class IClass { virtual void someFunc() = 0; }; class CFirst : public IClass { }; class CSecond : public IClass { }; boost::pt...

OpenMP num_threads(1) executes faster than no OpenMP

I’ve run my code in a variety of circumstances which has resulted in what I believe to be odd behavior. My testing was on a dual core intel xeon processor with HT. No OpenMP '#pragma' statement, total runtime = 507 seconds With OpenMP '#pragma' statement specifying 1 core, total runtime = 117 seconds With OpenMP '#pragma' statement sp...

Need to know about good C++ Reflection API (For RuntimeType Identification -RTTI and runtime calling)

Hello, I need to know about good C++ Reflection API(Would be better if Microsoft API is available) which enables me to determine the types(classes,structs,enums,ints,float,doubles...)identification at runtime, declaring them and finally to call methods on those types at run time too. Regards Usman ...

Can I use a static var to "cache" the result? C++

I am using a function that returns a char*, and right now I am getting the compiler warning "returning address of local variable or temporary", so I guess I will have to use a static var for the return, my question is can I make something like if(var already set) return var else do function and return var? This is my function: char * G...

Is learncpp.com good for beginners?

In my search for a good, freely available resource that will teach me C++ I stumbled on http://www.learncpp.com/. My question is for intermediate to experienced C++ programmers... Does this site seem to be a good resource for a beginner to learn C++ from? I've gone through the first few section of the site, and I feel like I am starti...

Looking for a variety of Windows Form tutorials for visual studio.NET C++

Looking for a variety of Windows Form (winforms) tutorials for visual studio.NET C++ I found a few basic ones: How to: Create a Windows Forms Application Walkthrough: Retrieving Dialog Box Information Collectively Using Objects Any others? Thank You. ...

Why is dereferencing a pointer called dereferencing?

Why is dereferencing called dereferencing? I'm just learning pointers properly, and I'd like to know why dereferencing is called that. It confused me as it sounds like you are removing a reference, rather than going via the pointer to the destination. Can anyone explain why it is called this? To me something like destination or pointe...

how to excute a simple query use sqlapi++ with oracle

here is the code: cmd1.setCommandText("select * from lp.human_tb_meta_sex"); cmd1.Execute(); while (cmd1.FetchNext()) { SAString sas=cmd1.Field("id").asString(); cout<<"sas id:"< it gave me ORA-00932 error...I dont know why..? ...

Equvalent c++0x program withought using boost threads..

I have the below simple program using boost threads, what would be the changes needed to do the same in c++0X #include<iostream> #include<boost/thread/thread.hpp> boost::mutex mutex; struct count { count(int i): id(i){} void operator()() { boost::mutex::scoped_lock lk(mutex); for(int i = 0 ; i < 10000 ; i+...

Qt Creator / QMake Linker Arguments

Hi guys. I'm using SFML, and I want to use Qt Creator in conjunction with it. When I'm compiling manually, I supply the following arguments to the linker -lsfmlsystem -lsfmlwindow. How do I do this if I'm using Qt Creator and (I think) QMake? ...

C++: Syntax for map where Data type is function?

In C#, what I want would look something like this: IDictionary<string, action()> dict = new Dictionary<string, action()>(); How do I do this in C++? This gives compiler errors: map<string, void()> exercises; ...

Detecting regular expression in content during parse

I am writing a simple parser for C. I was just running it with some other language files (for fun - to see the extent of C-likeness and laziness - don't wanna really write separate parsers for each language if I can avoid it). However the parser seems to break down for JavaScript if the code being parsed contains regular expressions.....

Best practice for C++ audio capture API under Linux?

I need to create a C++ application with a simple audio recording from microphone functionality. I can't say that there aren't enough audio APIs to do this! Pulse, ALSA, /dev/dsp, OpenAL, etc. My question is what is the current "Best practice" API? Pulse seems supported by most modern distros, but seems almost devoid of documentation....

OpenGL Nothing will Display

Why can't I get anything to display with this code? #include <iostream> #include "GL/glfw.h" #ifndef MAIN #define MAIN #include "GL/gl.h" #include "GL/glu.h" #endif using namespace std; void display(); int main() { int running = GL_TRUE; glfwInit(); if( !glfwOpenWindow( 640,480, 0,0,0,0,0,0, GLFW_WINDOW ) ) { ...

C/C++ - Convert 24-bit signed integer to float

I'm programming in C++. I need to convert a 24-bit signed integer (stored in a 3-byte array) to float (normalizing to [-1.0,1.0]). The platform is MSVC++ on x86 (which means the input is little-endian). I tried this: float convert(const unsigned char* src) { int i = src[2]; i = (i << 8) | src[1]; i = (i << 8) | src[0]; ...

Why function is weightless?

Why having function in my class doesn't change size of this class? This info must be stored somewhere, but where? ...

Detect When Network Cable Unplugged

Windows knows when you have removed the network cable from your NIC. Is there a programmatic way to determine this via API in C++? Note: I am not using .NET and this is for a closed LAN (not connected to Internet ever) ...