c++

Why is vector deleting destructor being called as a result of a scalar delete?

I have some code that is crashing in a large system. However, the code essentially boils down to the following pseudo-code. I've removed much of the detail, as I have tried to boil this down to the bare bones; I don't think this misses anything crucial though. // in a DLL: #ifdef _DLL #define DLLEXP __declspec(dllexport) #else #define ...

Are there any mature distributed caching solutions available for C++ besides memcached?

Most interested in peer-to-peer solutions - without central server. So, I imagine it like a library that brings to my application a functionality of transparent cache management with feature of remote instances synchronization. It should support cache record timeout and forcing invalidation. UPDATE: If not completely peer-to-peer - at l...

C++ Winsock 2 questions

I have read through the documentation for Winsock2 on MSDN, but I still need clarification on a few things, if anyone can help. I planned to make something like the the setup you get when you use WSAAsyncSelect(), but using a separate thread. Can I use WSAEventSelect() to link more than one socket to a single event object? If I used a ...

memory management

This is a memory management question about c++ code. using namespace std; #include <iostream> #include <string.h> int main() { string a="first"; string *b= new string; *b=a; a="second"; cout << *b << ", " << a; delete b; return 0; } We can deallocate the blocks of memory that stored the string that b pointed to. I'm assuming ...

cin object in cpp

Hi everyone, I started to learn cpp and encountered cin as a way to receive input from the keyboard. If I understood, cin is an object and >> is an operator defined for it. In the way it is defined, how does it "knows" to separate words from each other? and another thing, what is the meaning of: while(cin) is cin a bool type? what does ...

Problems with Function checking Array input with IF statements

The void checkboard function is not working. This is a tic tac toe game. So that function checks after each move if someone has won the game or if it is a tie. After someone wins or there is a tie the board is to be reset and the game startover. I just cannot get the void checkboard function to work. Please help me solve this problem. ...

Accessing members of templated class instantiated with different template arguments

My main project class is templated class, declared with: template<int dim, typename typ> where dim is number of dimensions (2 or 3), and typ is floating point data type (float or double). Based on these parameters, instances of this class have their members of specific type and vectors (math) have dim number of components. So instanc...

Crash when calling virtual function

Ok this is a really weird problem. I wanna start off by saying that I'm not a beginner in c++ and I'm certainly not advanced. I'm somewhere in the middle. What I'm trying to do is make a C++ OOP wrapper library (dll) of the Win32 API. Here are the classes of my library. I compiled it with Mingw using the command: g++ -shared -o bin\win3...

Compilation error while using VS 2005 library in VC6

I have a library which is compiled in VS 2005 and I am trying to link it with one of the old VC 6 workspace, while linking I am getting following errors. error LNK2001: unresolved external symbol _sprintf_s error LNK2001: unresolved external symbol _strncpy_s error LNK2001: unresolved external symbol _strcpy_s error LNK2001: unresol...

I want to call a C# delegate from C++ unmanaged code. A parameterless delegate works fine , but a delegate with parameters crashed my program.

The Following is code of a function from a unmanged dll. It takes in a function pointer as argument and simply returns value returned by the called function. extern __declspec(dllexport) int _stdcall callDelegate(int (*pt2Func)()); extern __declspec(dllexport) int _stdcall callDelegate(int (*pt2Func)()) { int r = pt2Func(); re...

using smart pointers with "this"

I'm learning the use of boost smart pointers but I'm a bit confused about a few situations. Let's say I'm implementing a state machine where each state is implemented by a single update method. Each state could return itself or create a new state object: struct state { virtual state* update() = 0; // The point: I want to return a ...

GUI application and singleton/dependency injection

Hello, I am working on an application with a GUI using wxWidgets. I got an object used as a "model": its data has to be used to draw the ui and the ui should modify it. Let's call this class Model. The structure of the applications looks like this: A wxApp-derived object, that possesses: a wxFrame-derived object, that possesses a wx...

Why is pair, make_pair, and rel_ops all in the same include file?

I know the standard library has its warts (find me a language with a standard library that doesn't) but I've always wondered why they felt the need to stuff two seemingly unrelated pieces of code into an include named "utility." Was there once a reason for this? Did this library once contain more things that were deemed helpful or beca...

C++ const getter method with lazy initialization

What is the proper way to implement a getter method for a lazily-initialized member variable and maintain const-correctness? That is, I would like to have my getter method be const, because after the first time it is used, it's a normal getter method. It is only the first time (when the object is first initialized) that const does not ap...

The "right" way to add python scripting to a non-python application

I'm currently in the process of adding the ability for users to extend the functionality of my desktop application (C++) using plugins scripted in python. The naive method is easy enough. Embed the python static library and follow any number of the dozens of tutorials scattered around the web describing how to initialize and call python...

Robert Martin fans: Which book to read first, esp for C++

My understanding of object-oriented design is very limited. My main CS teacher was an old-school C programmer with little/no C++ knowledge, so I only know the basics (polymorphism, inheritance, operator overloading, etc). Since I've been working with a peer, I've come to discover there are some useful rules to learn, and most of the ru...

I cannot create a precompiled header in wxDev-C++

Hi there! I've a problem with using precompiled headers in wxDev-C++. According to wxWidgets Wiki: ---> http://wiki.wxwidgets.org/Precompiled_Headers In wxDevCpp, using MinGW and wxWidgets, i found the matter working this way: Prepare a designated precompile-header file as usual like discussed in the chapters above! ...

Storing locations in Array as a variable to be changed in a if statement

Is there a way to store the x and y entered by the user into a location for the array. I have this: if (x == 1 && y == 1) { board[0][0] = playerMarker; } I want to make it so the x and y are stored into a variable that matches the name of a spot in an array. But I want to try and make it more like this: ...

how to convert WIN32_FIND_DATA to string?

im using WIN32_FIND_DATA to store the data findfirstfile outputs. i want the file location (C:\file) as a string but i don't know how to get it or any other data from it. Edit: here is my code PTSTR pszFileName; PTSTR pszFileName2[100]; if (search_handle) { do { pszFileName = file.cFileName; pszFileName2[loo...

SFINAE To detect non-member function existence

Does anybody know of a method for specializing a template depending on whether a non-member method is defined? I know there are numerous ways for specializing if a member function exists, but I've never seen a non-member example. The specific problem is specializing the operator<< for shared_ptr to apply the operator<< if the operator<< ...