c++

How do I have my apps dialog box pop up and take focus from the current running app?

I know this type of thing is looked negatively upon but I write software for people with disabilities and sometimes good gui practices don't make sense. In this case, the user interacts with a assistive interface and under certain conditions, my control app needs to prompt the user with a question. My background process creates a dialog ...

How can I Violate Encapsulation property?

How can I Violate Encapsulation property without having a compile time error? (in C++) just so curious.. This was actually a question asked by one of my professor.. Please don't misunderstand. This was asked when we had a discussion over compiler error's ...

#include in .h or .c / .cpp ?

Hi, When coding in either C or C++, where should I have the #include's? callback.h: #ifndef _CALLBACK_H_ #define _CALLBACK_H_ #include <sndfile.h> #include "main.h" void on_button_apply_clicked(GtkButton* button, struct user_data_s* data); void on_button_cancel_clicked(GtkButton* button, struct user_data_s* data); #endif callback...

Iterator for boost::variant

Hy there, I'm trying to adapt an existing code to boost::variant. The idea is to use boost::variant for a heterogeneous vector. The problem is that the rest of the code use iterators to access the elements of the vector. Is there a way to use the boost::variant with iterators? I've tried typedef boost::variant<Foo, Bar> Variant; std...

C++: Best way to copy a section of WCHAR[] into a wstringstream?

I have a WCHAR[], a wstringstream, and an arbitrary section of the WCHAR[] that I want to copy into the wstringstream. What is the best way to do this? It seems that there must be a better way than this: for (int i = start; i < start + length; i++) { wszStringStream << wchr[i]; } ...

Using memcpy in the STL

Why does C++'s vector class call copy constructors? Why doesn't it just memcpy the underlying data? Wouldn't that be a lot faster, and remove half of the need for move semantics? I can't imagine a use case where this would be worse, but then again, maybe it's just because I'm being quite unimaginative. ...

Best way to render Tesselated Objects (OpenGL)

I'm using the GLUTesselator for Polygons. Right now the vertex callback does glvertex2f and gltex2f. Would it be better simply to collect the verticies from the vertex callback in a std::vector then use gldrawarrays()? Or would this actually be less efficient since it has to put the verts and texture coordinates in a vector? Thanks ...

How do I output the preorder traversal of a tree given the inorder and postorder tranversal?

Given the code for outputing the postorder traversal of a tree when I have the preorder and the inorder traversal in an interger array. How do I similarily get the preorder with the inorder and postorder array given? void postorder( int preorder[], int prestart, int inorder[], int inostart, int length) { if(length==0) return; //termi...

determining True/False.

Hi there, the following code #include <iostream> using namespace std; int main(){ char greeting[50] = "goodmorning everyone"; char *s1 = greeting; char *s2 = &greeting[7]; bool test = s2-s1; cout << "s1 is: " << s1 << endl; cout << "s2 is: " << s2 << endl; if (test == true ){ cout << "test is true...

C++ - Basic WinAPI question

Hello! I am now working on a some sort of a game engine and I had an idea to put everything engine-related into a static library and then link it to my actual problem. Right now I achieved it and actually link that library and every functions seem to work fine, except those, which are windows-related. I have a chunk of code in my libr...

is there a way to use c++0x at xcode? I want to use gcc 4.4 or greater.

I want to use gcc 4.4 or greater for iphone developement. anyone know how? ...

function objects versus function pointers

Hi All, I have two questions related to function objects and function pointers, Question : 1 When I read the different uses sort algorithm of STL, I see that the third parameter can be a function objects, below is an example class State { public: //... int population() const; float aveTempF() const; //....

Simple/efficient text compression

What's the simplest, but efficient compression algorithm? Deflate, lzma, etc. aren't valid options. I need something that compiles really small, like: RLE, LZX, Huffman, etc.. Note: The data is 95% ASCII text Edit: Data is ~20kb at the moment, but i expect it to grow up to 1mb ...

Gradients and memory

I'm creating a drawing application with OpenGL. I'v created an algorithm that generates gradient textures. I then map these to my polygons and this works quite well. What I realized is how much memory this requires. Creating 1000 gradients takes about 800MB and that's way too much. Is there an alternative to textures, or a way to compres...

Compare List/set elements

I'm looking to compare two sets and display the missing elements in second set by iterating over the first set. I've done using lists but it seems like an overhead iterating over the unordered list to find the elements. #include <iostream> #include <list> using std::list; bool isExist(list <int> &original, int i) { list <int>::iterat...

C++ template instantiation with identity argument

hello. I have ran into yet another problem I do not understand. The following does not instantiate (argument instantiation fails), why? template<class E> void operator[](typename boost::mpl::identity<E>::type e) const; thank you for your help ...

Using C++ is a Linked-List implementation without using pointers possible or not?

My question is very simple, can one using C++, implment a link-list data structure without using pointers (next nodes)? To further qualify my question, I'm mean can one create a Linked-List data structure using only class instantiations. A common node definition might be like so: template<typename T> struct node { T t; node<T>* n...

How to debug c++ DirectShow filter

What debugging tools are available for directshow filters? Presently, I have a project that compiles and registers a video source filter that I then setup a graph in GraphEdit. I am using c++ in visual studio 2008. Is it possible to get a debugger attached to the filter in any way where I could set break points, inspect variables, etc...

Boost ASIO Headache

Man... thought using ASIO in Boost was going to be easy and intuitive. :P I am starting to get it finally but I am having some trouble. Here's a snippet. I am having several compiler errors on the async_accept line. What am I doing wrong? :P I've based my code off of this page: http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/t...

C++ Program Flow: Sockets in an Object and the Main Function

I have a rather tricky problem regarding C++ program flow using sockets. Basically what I have is this: a simple command-line socket server program that listens on a socket and accepts one connection at a time. When that connection is lost it opens up for further connections. That socket communication system is contained in a class. ...