c++

Problem with Berkeley DB and C++

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...

Design Problem - Using a 'variation' on State Pattern - C++

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 ...

C++: how to deal with const object that needs to be modified?

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...

How to convert long to LPCWSTR?

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(); } ...

How do I find out where an object was instanciated using gdb?

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...

Is reinterpreting a member function pointer a 'good idea' ?

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...

Error: expected constructor, destructor, or type conversion before ';' token?

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...

C++ matrix transposion. Boost uBLAS and double*?

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,...

Strange error with debugging and filestream in c++

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();...

Why do I have __stdcall?

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...

C++ boost startup tutorials

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...

Using dlopen, how can I cope with changes to the library file I have loaded?

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...

return the value in a stack - C++

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...

When are member data constructors called?

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? ...

Precompiled headers with DLL solutions. Cannot open precompiled header file

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...

Vector assignment problem

#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...

Restrict users to enter numbers valid only till 2 decimal places C/C++

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 ...

LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification

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...

Constructor injection

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());...

Calling methods in a win32 service with elevated privileges from an application

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...