c++

What is the difference between Java and C++?

What is the difference between Java and C++? Are both object-oriented? ...

Unit testing in C++

How do I get started doing unit testing in C++ ? I have used Junit when coding in Java and found it very useful. Is there something similar in C++ ? What do you recommend ? ...

OwnerDrawn control in MFC

Hi, I am creating a MFC application in which there is a skin library which handles the UI effect of rendering the controls (it gets called in oninitdialog). But, meanwhile, I have also the requirement of displaying an icon on the buttons. For this, I am marking the buttons as ownerdrawn=true, and able to display icon, but in this case,...

Dispatching exceptions in C++

How should exceptions be dispatched so that error handling and diagnostics can be handled in a centralized, user-friendly manner? For example: A DataHW class handles communication with some data acquisition hardware. The DataHW class may throw exceptions based on a number of possible errors: intermittent signal, no signal, CRC failure...

Why is there no Z80 like LDIR functionality in C/C++/rtl?

In Z80 machine code, a cheap technique to initialize a buffer to a fixed value, say all blanks. So a chunk of code might look something like this. LD HL, DESTINATION ; point to the source LD DE, DESTINATION + 1 ; point to the destination LD BC, DESTINATION_SIZE - 1 ; copying this many bytes LD (HL), 0X20 ...

Vim indentation for c++ templates?

Does anyone have or know about vim plugin/macro/function that indents nicely c++ templates? When I highlight template definition in vim .hpp/.h file and indent it with '=' I get something like this: > template < > class TFilter, > class TParser, > class TConsumer, > class TDataProce...

Unit-testing C++ templates

I've used function and class templates in implementation of my libraries. So far I've just instantiated a template in the library unit-tests (CppUnit), and then proceeded to test it almost like any other normal class or function. Recently I've been planning to add some templates also to the library APIs. Good interface is of course the ...

How to detect leaks under WinCE C/C+ runtime library?

I know the possibilities of basic leak detection for Win32 using the crtdbg.h header, but this header is unavailable in the CE CRT library headers (i'm using the lastest SDK v6.1). Anyone knows how I can automatically detect leaks in a WinCE/ARMV4I configuration with VC 9.0? I don't want to override new/delete for my class hierarchy, I...

Architectural Suggestions in a Linux App

Hi, I've done quite a bit of programming on Windows but now I have to write my first Linux app. I need to talk to a hardware device using UDP. I have to send 60 packets a second with a size of 40 bytes. If I send less than 60 packets within 1 second, bad things will happen. The data for the packets may take a while to generate. But if ...

The Definitive C++ Book Guide and List

Provide QUALITY books and an approximate skill level. Add a short blurb/description about each book that you have personally read/benefited from. Feel free to debate quality, headings, etc. Books that meet the criteria will be added to the list. Books that have reviews by the Association of C and C++ Users (ACCU) have links to the revie...

C++ 2D Arrays of an Object Constructor

In my Dev C++, I am trying to create a 2D Array class that acts like a Grid. But one of the problem is I am unsure what do for the constructor. When I try to compile, I get the following errors: In constructor 'Grid::Grid(int,int)': 'sqaures' is not a type 'yPos' cannot appear in a constant-expression [Build Error] [grid.o] Error 1 Her...

Registering derived classes in C++

EDIT: minor fixes (virtual Print; return mpInstance) following remarks in the answers. I am trying to create a system in which I can derive a Child class from any Base class, and its implementation should replace the implementation of the base class. All the objects that create and use the base class objects shouldn't change the way th...

Aligning Member Variables By Template Type

Hello I want to align my member variables based on a class template type but I'm not sure if it is actually possible. The following is a (very) simple example of what I'd like to do template<int Align> class MyClass { private: struct MyStruct { // Some stuff } __declspec(align(Align)); __declspec(align(Align)) int myAlign...

Programmatically reading a web page

I want to write a program in C/C++ that will dynamically read a web page and extract information from it. As an example imagine if you wanted to write an application to follow and log an ebay auction. Is there an easy way to grab the web page? A library which provides this functionality? And is there an easy way to parse the page to get ...

assert and NDEBUG

After reading some threads on misuses of exceptions (basically saying you don't want to unwind the stack if a functions preconditions are incorrect - possibly signalling that all your memory is corrupt or something equally dangerous) I'm thinking about using assert() more often. Previously I have only used assert() as a debug tool and I ...

Best way to use a VB.NET class library from a C++ DLL?

Hello, I need to use one of my VB.NET projects in a C++ project. The interface between the two will be for the C++ code to instantiate and call methods on one of the .NET assembly objects. Both compile to DLLs (and then the C++ DLL is loaded from the NTVDM as a VDD, but that's probably not relevant.) If possible I would like to avoid u...

Should I use static data members? (C++)

Let's consider a C++ class. At the beginning of the execution I want to read a set of values from an XML file and assign them to 7 of the data members of this class. Those values do not change during the whole execution and they have to be shared by all the objects / instances of the class in question. Are static data members the most el...

GCC Template issue

Visual Studio compiles this code fine, but gcc only lets it compile without the Template operator. With the Template operator it gives the following errors: Line 29: error: expected `;' before "itrValue" class Test { public: Test& operator<<(const char* s) {return *this;} // not implemented yet Test& operator<<(size_t s) {r...

Namespaces in C

Is there a way to (ab)use the C preprocessor to emulate namespaces in C? I'm thinking something along these lines: #define NAMESPACE name_of_ns some_function() { some_other_function(); } This would get translated to: name_of_ns_some_function() { name_of_ns_some_other_function(); } ...

SQL Native Client crashes when second connection is opened when connection pooling is on?

I'm working with a C++ application that uses SQL Native Client to communicate via ODBC with a SQL Server 2000 database. Before doing any database work, I allocate an environment handle as follows: retcode = SQLAllocHandle( SQL_HANDLE_ENV, SQL_NULL_HANDLE, &EnvironmentHandle ); This completes successfully. To enable connection pooling...