I'm trying to write a simple C++ program that uses Berkeley DB for storage. The key of the database is of type time_t and the data is an integer.
I need to take the difference between two adjacent data in a between two key. I open a cursor with the flag DB_SET_RANGE and then i use DB_NEXT to iterate.
My problem is that the cursor retur...
Overview:
I am trying to improve the design of a program that I am using state pattern for. I will post a brief description of the problem, an image of the class diagram/description of the current design, followed by header code for the relevant classes.
Problem:
I'm using a variation of the State Pattern for a program. In this ...
I have a place in the code that used to say
const myType & myVar = someMethod();
The problem is that:
someMethod() returns const myType
I need to be able to change myVar later on, by assigning a default value if the object is in an invalid state. So I need to make myVar to be non-const.
I assume I need to make myVar be non-referen...
Hi, how can I convert long to LPCWSTR in C++? I need function similar to this one:
LPCWSTR ToString(long num) {
wchar_t snum;
swprintf_s( &snum, 8, L"%l", num);
std::wstring wnum = snum;
return wnum.c_str();
}
...
I'm debugging an application and it segfaults at a position where it is almost impossible to determine which of the many instances causes the segfault.
I figured that if I'm able to resolve the position at which the object is created, I will know which instance is causing the problem and resolve the bug.
To be able to retrieve this inf...
I have a worker thread, which holds a list of 'Thread Actions', and works through them as an when.
template <class T> class ThreadAction
{
public:
typedef void (T::*action)();
ThreadAction(T* t, action f) :
func(f),obj(t) {}
void operator()() { (obj->*func)(); }
void (T::*func)();
T* obj;
};
It's normally called like...
I'm trying to compile my code to test a function to read and print a data file, but I get a compiling error that I don't understand - "error: expected constructor, destructor, or type conversion before ';' token". Wall of relevant code-text is below.
struct Day
{
int DayNum;
int TempMax;
int TempMin;
double Precip;
int TempRa...
Hello!
I need to do a in-place transposition of a large matrix(so the simplest way to allocate another matrix and transpose to it won't work). Unfortunately, this large matrix isn't square. And worse, the matrix is stored in an array of doubles with number of columns and rows stored separately.
I found that boost has the uBLAS library,...
Hi to all,
the program I am working on has a function to read some parameters from a text file basically looking like this:
void ParamSet::readFrom(const std::string filename){
std::ifstream infile(filename.c_str());
std::string line;
if(!infile.is_open())
throw(20);
/* ... read stuff ... */
infile.close();...
I am starting doing some directX programming. I am using this tutorial that I have found from the Internet.
I am just wondering why the CALLBACK has been defined as _stdcall and why WINAPI is as well.
I thought __stdcall was used when exporting functions that will be compiled as a dll.
However, as WindowProc and WINAPI will never been...
I am learning boost c++ libraries, installed boost and started reading their tutorial at http://www.boost.org/doc/libs/1%5F37%5F0/doc/html/variant/tutorial.html . I felt like I do not know anything even from c++ . I was stumped at some weird term called visitor. It didn't explained me clearly what that meant. Can somebody please point me...
I have a program written in C++ which uses dlopen to load a dynamic library (Linux, i386, .so). When the library file is subsequently modified, my program tends to crash. This is understandable, since presumably the file is simply mapped into memory.
My question is: other than simply creating myself a copy of the file and dlopening th...
I have the following defined:
Stack<ASTNode*>* data;
The way the class is defined, if I do data->push() or data->pop(), I directly push onto the stack or pop off the stack. To get the node at the top of the stack I would do data->peek(). For testing purposes, I would like to print out the top node in the stack like this:
cout << "top...
I have a global member data object, defined in a header (for class MyMainObj) like this.
class MyMainObj
{
MyDataObj obj;
}
MyDataObj has a default constructor.
When is the constructor for MyDataObj called?
Is it called as part of the creation of MyMainObj?
...
This worked without error when this solution worked off of .lib files instead of .dll files.
I have all of my projects except one currently using a precompiled header, without error. The precompiled header is called "LudoGlobal.h". I am trying to link the last project to this precompiled header (which exists in a seperate, "Core", p...
#include "iostream"
#include "vector"
using namespace std;
const vector<int>& Getv()
{
vector<int> w(10);
w[0]=10;
cout<<w.size()<<endl;
return w;
}
//Now when I write in main:
vector<int>v = Getv();//Throws exception
//and the below rows has no effect
vector<int>v;
v=Getv()//w does not change
please what is the problem?
Hani Almousl...
I am making an currency change program where I would be providing exact change to the input amount, for example a value of 23 would be one 20 dollars and 3 one dollar bills
I want to restrict the user to input the value only till 2 decimal places. For example: the valid inputs are
20, 20.4, 23.44 but an invalid input would be 20.523 or ...
I recently converted a multi-project solution to use .dlls instead of .libs for each of the projects. However, I now get a compiler warning for each project as stated in the example. MSDN didn't serve to be all that helpful with this. Why is this and howcan I solve it?
Warning 2 warning LNK4075: ignoring
'/EDITANDCONTINUE' due...
I know the code is missing (Someone will give negative numbers). But I only want to know how do you solve constructor injection in this situation?
class PresenterFactory
{
public:
template<class TModel>
AbstractPresenter<TModel>*
GetFor(AbstractView<TModel> * view)
{
return new PresenterA(view, new FakeNavigator());...
I have developed a Win32 C/C++ application that creates dynamic WFP IP filters, however it must be run as admin to do so (due to the Windows security policy). I want to place the code that requires admin privileges in a service running with admin privileges and then call it from the application running as a normal user.
First is this th...