c++

When do we have to use copy constructors?

As I know that C++ compiler creates a copy constructor for each class. In which cases we have to write user defined copy constructors? Can you give some examples? ...

Flipping line endings in C++ (or R)

I have a C++ that I'm running though R (via Rcpp). Recently, I found that the C++ program I'm wrapping with Rcpp fails when using Windows-style line endings. I'm wondering if anyone knows of a cross-platform way for me to change Windows-style line endings to Unix-style line endings in either C++ or R or ash shell (which comes install...

Any obvious problems or improvements for my producer consumer queue.

I asked a previous question about producer/consumer code that was overly general (though the answers were certainly helpful). So I've taken the suggestions from an earlier SO question by another author and converted them to C++ and boost. However I'm always a bit concerned about multithreaded code - so if anyone can see any obvious impro...

What is the difference between header file and namespace ?

I want to know the exact difference between Header file and namespace in consideration in programming languages ?? ...

cmake: Building multiple versions of a program

I would like to write a cmake script that will compile the same source against multiple versions of header files. The aim is to be able to easily create shared libraries that are backwards compatible with earlier versions of an API. I am looking for examples and pointers on the best way to do this. I am new to both c++ and cmake so an...

trying to understand the c preprocessor

why do these blocks of code yield different results? some common code: #define PART1PART2 works #define STRINGAFY0(s) #s #define STRINGAFY1(s) STRINGAFY0(s) case 1: #define GLUE(a,b,c) a##b##c STRINGAFY1(GLUE(PART1,PART2,*)) //yields "PART1PART2*" case 2: #define GLUE(a,b) a##b##* STRINGAFY1(GLUE(PART1,PART2)) //yields "works*"...

Serializing a map of objects to xml using boost::serialization

The serialization example below is from the boost mailing list which is pretty much the same as what I would like to do. However, I have changed the archive so that it will serialize to XML. The compile does not fail if I serialize to binary, but it fails when serializing to xml. The compile fails in basic_xml_oarchive.hpp in the followi...

C++ Multiple Callback funtions problem

Hi, I have a dll which requires me to set a callback function for it (actually it's a camera sdk and it will callback my function when it receives a picture). I wanna have multiple (user input) cameras but I can't. Since I should make unknown number of callback functions. the easy way is to make a class (camera) which have a function f...

C++: How to implement (something like) JSON

Not sure how to explain it - I'm pretty new to C++, but... let me try: Let's say I have 300+ names (Jeff, Jack...) with 300+ int values (0 or 1). In JS I would use JSON. Something like this: var people = {"person": [ {"name": "Jeff","val": 0}, {"name": "Jill","val": 1}, {"name": "Jack","val": 0...

Webrequest for text file using C++

How to make webrequest in VC++ 2008 for text file? ...

Can "signed char" and "unsigned char" always be cast to each other without loss of data?

In C++ we can have signed char and unsigned char that are of same size but hold different ranges of values. In the following code: signed char signedChar = -10; unsigned char unsignedChar = static_cast<unsigned char>( signedChar ); signedChar = static_cast<signed char>( unsignedChar ); will signed char retain its value regardless of ...

Determine inheritance at compile time

Hi, I have some code that behaves like this: class Base {}; class MyClass : public Base {}; MyClass* BaseToMyClass(Base* p) { MyClass* pRes = dynamic_cast<MyClass*>(p); assert(pRes); return pRes; } Is there a way to add a compile time check so I can catch calls to this function where p is not an instance of MyClass? I had a ...

Memory problems

Hello, I have some singleton class (please, don't speak about singleton usage). class InputSystem : boost::serialization::singleton<InputSystem> { private: boost::shared_ptr<sf::Window> mInputWindow; public: InputSystem() { mInputWindow = boost::shared_ptr<sf::Window>( new sf::Window(someARgs) ); someMethod(); } ...

On Non-Admin Account OpenSCManager() function returns null

Dear Sir Please help me soon. I am writing a c++ code to run a service, it works fine on administrator account but on Non-Admin user account, OpenSCManager() function return null. Please tell me how to grant permission to non-admin user account to start and stop services. Or do i need to do something else. Please reply soon ...

lightweight html control for desktop apps (C++/Windows)

I am currently using RichText control in my program. It creates several instances of RichText control (hundreds) because it’s a sticky notes program. I wish to replace it with a lightweight HTML control which will have functionality similar to RichText control (text formatting, bullets, links, images etc) Do you know if any free/commer...

What is the copy-and-swap idiom?

What is this idiom and when should it be used? Which problems does it solve? Will the idiom change when C++0x is used? Although it's been mentioned in many places, we didn't have any singular "what is it" question and answer, so here it is. Here is a partial list of places where it was previously mentioned: What are your favorite C++ ...

How to compile (build) my Qt application to run on many linux distributions?

Hi, I have created a Qt GUI application and I want to provide a linux executable that runs on as many distributions as possible. Is this possible or do I have to provide a separate executable for each distribution? Thanks for your help ...

Create Hidden (CWnd derived class ) class in a regular dll and unable to post the messages to it from it

i had written code for creating hidden window, but in a dll & messages are not getting posted to the hidden window. my requirement is to post the messsages to the hidden window from the hidden window itself. i'll just call start function of this hidden window then it will create & process the user defined message (this is my requirement...

ofstream doesn't write buffer to file

I'm trying to write the contents of buf pointer to the file created by ofstream. For some reason the file is empty, however the contents of buf is never empty... What am I doing wrong? void DLog::Log(const char *fmt, ...) { va_list varptr; va_start(varptr, fmt); int n = ::_vscprintf(fmt, varptr); char *buf = new char...

Forward declaring classes in namespaces

I was rather surprised to learn that I couldn't forward declare a class from another scope using the scope resolution operator, i.e. class someScope::someClass; Instead, the full declaration has to be used as follows: namespace { class someClass; } Can someone explain why this is the case? UPDATE: To clarify, I am asking why t...