c++

C++ float to int

Maybe, it's very simple question but I couldn't get the answer. I've been searching quite a while ( now Google think that I'm sending automated queries http://twitter.com/michaelsync/status/17177278608 ) .. int n = 4.35 *100; cout << n; Why does the output become "434" instead of "435"? 4.35 * 100 = 435 which is a integer value and t...

Multi-window program

Hello. I read many articles on the topic, a few of them were here, on stackoverflow, but none of them asked my question. I'll try to be specific. I need to create an application (native WinAPI) with a main window (of window class "a"). When the user clicks a button there, a window of "b" class pops up. It might be modal or not, I don't ...

Move constructor/operator=

I'm trying to learn about new feature of C++ namely move constructor and assignment X::operaror=(X&&) and I found interesting example but the only thing I quite not even understand but more dissagree is one line in move ctor and assignment operator (marked in the code below): MemoryBlock(MemoryBlock&& other) : _data(NULL) , _leng...

Best way to test code speed in C++ without profiler, or does it not make sense to try?

On SO, there are quite a few questions about performance profiling, but I don't seem to find the whole picture. There are quite a few issues involved and most Q & A ignore all but a few at a time, or don't justify their proposals. What Im wondering about. If I have two functions that do the same thing, and Im curious about the differenc...

c++ template seems to break access specifiers

The following code doesn't compile for obvious reasons, namely that Foo is trying to access a private member of Bar. However if you uncomment/comment the lines marked, making Foo a template, it does compile and outputs 42. What am I missing here? Why does this work? Seems to me it shouldn't. Thanks for your help. #include <iostream> c...

OpenCV 1.1 K-Means Clustering in High Dimensional Spaces

Hi I am trying to write a bag of features system image recognition system. One step in the algorithm is to take a larger number of small image patches (say 7x7 or 11x11 pixels) and try to cluster them into groups that look similar. I get my patches from an image, turn them into gray-scale floating point image patches, and then try to ge...

Is is possile to Hook file-download event of a program ?

Please tell me is it possile to know when a program is trying to download a file ( like in Internet Download Manager ). I want to catch that event (hook it), get the download url, and then destroy the event. Thanks in advance.. @Jerry Coffin:Sr, I forgot to tell you that this feature of IDM is not active by default. It is only turned on...

Namespace Aliasing in C++

It is widely known that adding declarations/definitions to namespace std results in undefined behavior. The only exception to this rule is for template specializations. What about the following "hack"? #include <iostream> namespace std_ { void Foo() { std::clog << "Hello World!" << std::endl; } using namespace std; } int...

How to connect C++ code to an application?

Suppose I have some function, say in C++ int f() { // do some stuff } How do I connect it to a button in some application? It does not need to be a web application per se, it can be a normal desktop application (not a big difference, I guess). What all do I need to do to get this function to be called when I press a button in som...

Find array element by member value - what are "for" loop/std::map/Compare/for_each alternatives?

Example routine: const Armature* SceneFile::findArmature(const Str& name){ for (int i = 0; i < (int)armatures.size(); i++) if (name == armatures[i].name) return &armatures[i]; return 0; } Routine's purpose is (obviously) to find a value within an array of elements, based on element's member variable, where ...

install driver using c++

I'm trying to install driver behind the user: I've create DLL which call SetupCopyOEMInf using c++ then i call it from VB application: C++ code: PBOOL bRebootRequired = false; PCTSTR szInfFileName = (PCTSTR) "c:\\temp\\ttt\\Driver\\slabvcp.inf"; if(!SetupCopyOEMInf(szInfFileName,NULL, SPOST_PATH, SP_COPY_REPLACEONLY, NULL, 0, NULL, N...

Questions about "this pointer adjustor" in C++ object layout.

I am kind of confused by one question: Under what cirumstances does the MS VC++ compiler generate a this adjustor? Notice that the this adjustor is not necessarily in a thunk. Below is my test code. class myIUnknown { public: virtual void IUnknown_method1(void)=0; virtual void IUnknown_method2(void)=0; int data_unknown_1; ...

Modelling Typeclasses in C++

Is it possible to implement Haskell typeclasses in C++? If yes, then how? ...

When all does comma operator not act as a comma operator?

If you see this code, class A{ public: A(int a):var(a){} int var; }; int f(A obj) { return obj.var; } int main() { //std::cout<<f(23); // output: 23 std::cout<<f(23, 23); // error: too many arguments to function 'int f(A)' return 0; } f(23, 23) does not compile because the comma acts as a separator here a...

SFML Input GetMouseX and GetMouseY not catching on to mouse movement

I'm programming a GUI in my app and I noticed that button presses weren't being registered very quickly. I did some lazy debugging (send coordinates of mouse to output) and I noticed that Input's GetMouseX and GetMouseY weren't responding nearly fast enough to when the mouse moved somewhere. This small tidbit should be able to reproduce...

Build a simple web server that I can run as a windows service.

I'm a web developer so all my experience is with ruby, python, or PHP. However, I'm gonna do a little windows programming. I want to build a light weight web server that can handle incoming requests and pass them on to a COM port. I want to be able to distribute it as an exe that will install the server as a windows service. What do yo...

Compiler error coming out of yaml-cpp

I'm attempting to integrate yaml-cpp into a project, but I'm seeing some unexpected errors out of GCC. For example: g++ -c -ggdb3 -ansi -Wall -Werror -pedantic-errors src/commands-tz.cpp -o obj/commands-tz.o In file included from /usr/local/include/yaml-cpp/conversion.h:9, from /usr/local/include/yaml-cpp/node.h:8, ...

Observer design pattern and others

I'm starting to read about design patterns and trying to apply them to some coding. I've read about the observer pattern and think it would be a most useful one to make use of. My two questions are these: 1) If I want my object to be both an observer and a subject, is it simply a question of making it inherit from both the observer and...

Problem with Threads in MFC project

Mabye someone over here can explain to me what am i doing wrong...This is after reading a lot of articles over the net and doing what say said over there...and not working.... My problem is that i am developing a nice little game with a background music and explosion sound, for the explosion i know i need to use threads or my music stop...

Reference to a pointer

char *str = "Hello"; char *ptr = str; char *&rptr = str; What is the difference between ptr and rptr? I understand rptr is a reference to a pointer(in theory) but how does it differ in terms of implementation with ptr? Are references in C++ implemented using pointers? ...