Consider a sequence of n positive real numbers, (ai), and its partial sum sequence, (si). Given a number x ∊ (0, sn], we have to find i such that si−1 < x ≤ si. Also we want to be able to change one of the ai’s without having to update all partial sums. Both can be done in O(log n) time by using a binary tree with the ai’s as leaf node v...
Hi, I am trying to understand interrupts and am looking for a simple code that uses interrupts. Could somebody please help me with it?
...
I need a container of pointers. Would you recommend boost::ptr_vector<T> or std::vector<boost::shared_ptr<T> >? (Or something else?)
If that's of interest, my actual data structure is relatively complicated (see here) and currently stores objects, not pointers, but i'd like to change that (using pointer containers), in order to get rid ...
Hi everybody!
When a window handle is given, how can i exactly resize a window sending windows messages towards it? I've tried many things such as sendig a WM_SIZING Message to the window, but nothing worked(the way i did it).
I don't like to use SetWindowPosition.
Thanks in advance,
David
...
Currently I'm using GetFileSizeEx to track how large a log files gets before I write to it. We have limited space and anything if we try to create a file larger than 100 megabytes we stop logging data. The problem is for some reason GetFileSizeEx will corrupt the file handle that I am using.
if( hFileHandle != INVALID_HANDLE_VALUE && hF...
I need a data structure that manages integer IDs for T objects (typically std::string). It
should support getting the ID for some object and, vice versa, get the object for some ID:
// if object not seen before: copies and stores object and returns
// new ID, otherwise just returns its ID
int Add(const T& obj);
// if obj not found: ret...
Hi Guys - this is a strange one...
I am playing with some decompression algo. Instead of going through the char buffer[] and looping until a stop-bit in buffer[i] is found, I am trying use some bit-mask techniques but with chars.
I have the following example:
// In a *.h file
const char ch = '\x81';
// To avoid Endianess
unio...
To be consistent with other classes in a library, my array class below has two read() methods. The first reads the entire array to an output iterator and returns an error code, the second reads a single value and returns that (using exceptions for errors).
The problem I have is that if I call the second read(size_t idx) method with an ...
I am trying to import a function from an unmanaged code c++ dll into my c# application. The c++ prototype is
int somefunction (int param1, int *param2 = NULL);
How do I declare this in c# to take advantage of the optional nature of param2? The following code does not work. param2 gets initialized with garbage.
DllImportAttribute("...
If I need to get a NUL-terminated char array out of a std::string in a situation where I need to be sure nothing will be allocated, is it safe to use c_str to do so? For example, if I'm inside a destructor and I want to copy some data from a string into a pre-allocated, fixed-size buffer, can I use c_str and be sure it won't throw anythi...
I'm a fairly new programmer, but I consider my google-fu quite competent and I've spent several hours searching.
I've got a simple SDL application that reads from a binary file (2 bytes as a magic number, then 5 bytes per "tile")
it then displays each tile in the buffer, the bytes decide the x,y,id,passability and such.
So it's just lev...
When I go thru the code written by collegue, in certain place, they use:
this->doSomething(); //-->case A
doSomething(); //-->case B
In fact I'm not sure about the great usage of *this pointer...:(
Another question with argument matching:
obj.doOperation(); //-->case C
(&obj)->doOperation(); //-->case D
In fact both cases are per...
I have a simple C++ base class, derived class example.
// Base.hpp
#pragma once
class Base
{
public:
virtual float getData();
virtual void setData(float a, float b);
virtual void setData(float d);
protected:
float data;
};
//Base.cpp
#include "stdafx.h"
#include "Base.hpp"
float Base::getData()
{
return data;
...
Is it possible to define a default minimum height for a QPushButton through a custom application wide QStyle?
I know this can be achieved using stylesheets, but I rather not use them because of performance reasons.
...
Hi
I've been reading some on forward declarations, including in this forum. They all say that it saves us from including the header file, However the following code generates an error:
#ifndef CLASSA_H_
#define CLASSA_H_
class B;
class A {
public:
A();
~A();
int getCount();
private:
static int _count;
int _num;
...
I'm doing something wrong but I do not know what. Here are my files:
//main
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
//MyFoo.h
#pragma once
#include "stdafx.h"
class MyFoo
{
public:
MyFoo(void){};
int multiplyByTwo(int value);
~MyFoo(void){};
};
//MyFoo.cpp
#include "stdafx.h"
#inclu...
I am calling a function in a API that returns a Answer object. Under some conditions, the API will return EMPTY_answer, which is defined as such:
#define EMPTY_answer ((Answer)0)
of course, attempting to access a Answer variable or function from an EMPTY_answer object crashes the application.
Trying to test for it using if(lAnswer ...
Is there a nice bash one liner to map strings inside a file to a unique number?
For instance,
a
a
b
b
c
c
should be converted into
1
1
2
2
3
3
I am currently implementing it in C++ but a bash one-liner would be great.
...
My issue is that I am trying to create a Opengl/Win32 application and I am unable to keep my dialog box open. It literally flashes as if someone pressed cancel on it RIGHT when it opened.
I've looked around google and found a few others with this issue, but none of the solutions they posted have helped me, so I turn to the StackOverflow ...
Hi...
I have seen too much C# and C++ code where the variable naming convention seems to ask programmers to write variable names using underscore before the text of the variable. e.gr.
int? _countMoney;
What's the rationale supporting that convention?
...