c++

Should non-public functions be unit tested and how?

I am writing unit tests for some of my code and have run into a case where I have an object with a small exposed interface but complex internal structures as each exposed method runs through a large number of internal functions including dependancies on the object's state. This makes the methods on the external interface quite difficult...

Interprocess Communication Between C# application and unmanaged C++ application

Hi All, I have two windows services, the first one written in c# and the second written in unmanaged c++, I want to know how can I do two-way interprocess communication. Thanks All ...

Isn't it possible to use 'Repeats' in the lookaheads for boost:regex?

I'm trying to extract some variables in my C++ code nested in blocks for example, if I have DEL_TYPE_NONE, DEL_TYPE_DONE, DEL_TYPE_WAIT, I'd like to match "DEL_TYPE_NONE" "DEL_TYPE_DONE" "DEL_TYPE_WAIT" I made my pattern like this, std::string pat("(?<=^[ \\t]?)[A-Z0-9_]+(?=,$)"); but I'm keep getting error message when compil...

Return an array by looking up bits?

I have the following use case , array of integers vector<int> containing elements 123 345 678 890 555 ... pos 0 1 2 3 4 Based on the bits representation I receive for e.g 101 then return 123 678 (Elements of the array with its position bits set) 0011 then return 678 890 00001 then retur...

What is the conventions for headers and cpp files in C++?

In C++, what is the convention for including headers for class files in the "main" file. e.g. myclass.h class MyClass { doSomething(); } myclass.cpp doSomething() { cout << "doing something"; } run.cpp #include "myclass.h" #include "myclass.cpp" etc.. Is this relatively standard? ...

Can any IDE or framework help testing code like this...?

I mainly develop in native C++ on Windows using Visual Studio. A lot of times, I find myself creating a new function/class or whatever, and I just want to test that piece of logic I just wrote, quickly. A lot of times, I have to run the entire application, which sometimes could take a while since there are many connected parts. Is the...

How to Overcome Errors Thrown by mmsystem.h

Hi, I am not able to get out of these simple bugs, but would be great full if some one could answer to weed out from these errors. I included windows.h and some other necessary headers but couldn't able get out of it. Snippet of errors: error C2146: syntax error : missing ';' before identifier 'MMVERSION' error C4430: missing type sp...

Named constructor and inheritance

I'm working on C++ framework and would like to apply automatic memory management to a number of core classes. So far, I have the standard approach which is class Foo { public: static shared_ptr<Foo> init() { return shared_ptr<Foo>(new Foo); } ~Foo() { } protected: Foo() { } }; // Example of use shared_...

Will the ".target-name" targets in make files always run?

I'm new to make and makefiles, so forgive me if this is very basic. I'm looking through some makefiles in my project and I'm seeing 2 types of targets -- targets that don't begin with a . character and targets that do. And from what I'm guessing, it seems like the ".target-name" targets are always executed, is my assumption true? I did...

compile directly from vim

I'd like to compile cpp file w/o turning off vi. I know the :!g++ file.cpp but I prefer :make so I added this line in .vimrc file au FileType C set makeprg=gcc\ % au FileType Cpp set makeprg=g++\ % but I keep getting "make: * No targets specified and no makefile found. Stop.** "message. can anyone tell me what is wrong with my ...

void, VOID, C and C++

I have the following code: typedef void VOID; int f(void); int g(VOID); which compiles just fine in C (using gcc 4.3.2 on Fedora 10). The same code compiled as C++ gives me the following error: void.c:3: error: ‘<anonymous>’ has incomplete type void.c:3: error: invalid use of ‘VOID’ Now, this is something in external library and I ...

Runtime dependency for std::string concatenation

std::string sAttr(""); sAttr = sAttr+VAL_TAG_OPEN+sVal->c_str()+VAL_TAG_CLOSE; else where in the code I have defined const char VAL_TAG_OPEN[] = "<value>"; sVal is a variable that is retrieved off of a array of string pointers. This works fine in most of the system, windows and linux. However at a customer site, where to my belief...

Allocating memory for triple pointer

Hi, I have a function which takes a triple pointer as an argument: int somefunction(tchar ***returnErrors); Does anyone know how to allocate the memory for the returnErrors parameter? Thanks! Niko ...

Which version of safe_delete is better?

#define SAFE_DELETE(a) if( (a) != NULL ) delete (a); (a) = NULL; OR template<typename T> void safe_delete(T*& a) { delete a; a = NULL; } or any other better way ...

Please, help with STL stringstream

Why do I fail to extract an integer value into Num variable ? #include <sstream> #include <vector> #include <iostream> using namespace std; int main() { string Digits("1 2 3"); stringstream ss(Digits); string Temp; vector<string>Tokens; while(ss >> Temp) Tokens.push_back(Temp); ss.str(Tokens[0]); ...

boost::asio::serial_port reading after reconnecting Device

I have a problem with the boost::asio::serial_port class reading from a GPS device (USB-Serial). Connecting the device and reading from it works fine, but when I disconnect and reconnect the device, read_some doesn't read any bytes from the port. As boost doesn't seam to detect that the serial port is gone ( is_open() returns true ), I ...

Catching c++ base exceptions

In my project we have a base exception. For handling showing error dialogs, log and such. Im looking for a way to handle all derived classes of that exception, I thought this would work: try { main_loop(); } catch (const MyExceptionBase* e) { handle_error(e); } As every child instance thrown could be represented by a pointer to it...

How to build a C++ Dll wrapper that catches all exceptions?

Like the title says, we’re looking for a way to catch all exceptions from a piece of C++ code, and wrap this in a dll. This way we can shield of the application that uses this dll, from any errors occurring in this dll. However, this does not seem possible with C++ under Windows. Example: void function() { try { ...

Why do profilers need administrative privs (on Windows)

I've been evaluating profilers and memory checking tools for native C++ programs on Windows and all of them want to be installed and run with administrator privileges. I rarely log in as admin on my machine. If I need to install something or do something that requires administrative privileges, I use runas and it works pretty well. Is i...

Using Boost Tokenizer escaped_list_separator with different parameters

Hello i been trying to get a tokenizer to work using the boost library tokenizer class. I found this tutorial on the boost documentation: http://www.boost.org/doc/libs/1 _36 _0/libs/tokenizer/escaped _list _separator.htm problem is i cant get the argument's to escaped _list _separator("","",""); but if i modify the boost/tokenizer.hpp...