c++

Should C++ eliminate header files?

Many languages, such as Java, C#, do not separate declaration from implementation. C# has a concept of partial class, but implementation and declaration still remain in the same file. Why doesn't C++ have the same model? Is it more practical to have header files? I am referring to current and upcoming versions of C++ standard. ...

Trouble using .NET DLL in Borland C++ Builder 4

I have created a COM callable DLL in C# .NET 2.0 and created a TLB from the assembly using the .NET regasm tool. In Borland C++ Builder 4.0 I go to Project->Import Type Library-> and find my DLL's type library there and click "Ok" to import it. BCB creates an HardwareCheck_TLB.cpp & HardwareCheck_TLB.h file. In a cpp file of the ...

File transfer between 2 remote systems using internal modem

My requirement is to write an application to send a file from a remote machine to another machine using internal modem. Both system are connected thru VPN or a internet. Basically we have two systems both having internal dial up modems. The two systems are connected through either VPN or Internet. One system should send a file (XML) to...

Returning Large Objects in Functions

Compare the following two pieces of code, the first using a reference to a large object, and the second has the large object as the return value. The emphasis on a "large object" refers to the fact that repeated copies of the object, unnecessarily, is wasted cycles. Using a reference to a large object: void getObjData( LargeObj& a ) { ...

Should network packet payload data be aligned on proper boundries?

If you have the following class as a network packet payload: class Payload { char field0; int field1; char field2; int field3; }; Does using a class like Payload leave the recipient of the data susceptible to alignment issues when receiving the data over a socket? I would think that the class would either need to be reo...

Templated namespaces and typedefs are illeagal -- workarounds?

I have a templated function fct that uses some complex data structure based on the template parameter. It also calls some helper functions (templated on the same type) that are in a separate helpers namespace and use the same complex data structure. Now it gets really ugly because we cannot make one typedef for the complex type that all ...

Problem clearing Listview Header image on Vista

I'm having a problem on Vista with the Listview control, in particular setting custom icons on the header. Normally under XP or any of the previous version of Windows, if I added an icon (in C++), I could do so with the following: HeaderItem.mask = HDI_FORMAT | HDI_IMAGE; Header_GetItem(HeaderHWND, Column, &HeaderItem); TurnOn(Hea...

Is there any way to prevent Boost.Build from recursively scanning header files for #include directives?

Is there a way to limit the header files that Boost.Build recursively scans for #include directives to a particular directory or set of directories? I.e. I'd like it to recursively scan the header files within my project only. I know that they external dependencies are not going to change (and being Boost and Qt they're pretty big). I en...

Cross-Platform Generic Text Processing in C/C++

Hi, What's the current best practice for handling generic text in a platform independent way? For example, on Windows there are the "A" and "W" versions of APIs. Down at the C layer we have the "_tcs" functions (like _tcscpy) which map to either "wcscpy" or "strcpy". And in the STL I've frequently used something like: typedef std::ba...

C++ Multiply defined symbols using a header defined template class.

I'm working on a project with a DLL and an EXE in visual studio 2005. Amongst the code for the DLL is a template for a growable array class: template <class Type> class GArray { Type *p; uint32 len; uint32 alloc; protected: bool fixed; public: /// Constructor GArray(int PreAlloc = 0) { p = 0; len = 0; fixed = false; al...

Copy constructor initialization lists

I know that if you leave a member out of an initialization list in a no-arg constructor, the default constructor of that member will be called. Do copy constructors likewise call the copy constructor of the members, or do they also call the default constructor? class myClass { private: someClass a; someOtherClass b; public:...

C++ Random Seed, Global Objects, and SDL_Threads

In my program, I have an object the global cpp file, that takes an integer as an argument. //In global header extern Object example; //In global cpp file Object example( (rand() % 6) ); I want a random number to be generated to the object's argument, but the seed does not reach the global variable, as the seed created in another cpp ...

Yaml Emitter in C++

Is there a C++ library for emitting YAML? Wikipedia mentions a c++ wrapper for libyaml, but the link is broken. The official YAML site only offers yaml-cpp, which was also suggested in this SO question, but cpp-yaml is only a parser, not an emitter. Am I out of luck? Edit: I'm looking for an object oriented interface, hence the C++ r...

How to use pcap_sendqueue_queue() in winpcap library?

Hi, I used pcap_sendPacket() to send raw UDP packet which i crafted manually. i want to increase the performance of my code by reducing the context switches. But i got the sample code about pcap_sendqueue_queue() function it sends variable number of packets in a time.but it reads read from the already dumped .pcap file and .cap fi...

View Compiler Mangled Names in C++

How do I view the compiler-generated mangled names for overloaded functions in C++? I'm using VC9 but answers for other compilers are welcome too. Edit: I find all the answers useful here. Accepting the one I liked best. ...

Overloading a method on default arguments

Is it possible to overload a method on default parameters? For example, if I have a method split() to split a string, but the string has two delimiters, say '_' and "delimit". Can I have two methods something like: split(const char *str, char delim = ' ') and split(const char *str, const char* delim = "delimit"); Or, is there a ...

COM API - could not pass "NULL" for a pointer argument

I have a COM API foo, the IDL looks like: foo([in] unsigned long ulSize, [in, size_is(ulSize)] unsigned char* pData) when I consume this function with foo(0,NULL); I get an error - NULL argument passed. Is there a way to workaround this? ...

Deleting a const pointer

I have a basic question regarding the const pointers. I am not allowed to call any non-const member functions using a const pointer. However, I am allowed to do this on a const pointer: delete p; This will call the destructor of the class which by in essense is a non-const 'method'. Why is this allowed ? Is just to support this: dele...

How to share image data between applications?

I already have an application called "old" which renders an image in which the image data is stored in form of session, and I need to read that data from this existing "old" application to an application called "new". How do I pass this data? Do I need to get the memory address of the session and pass it to my other application? And ev...

Are const_iterators faster ?

Our coding guidelines say prefer const_iterator, because they are little faster compared to normal iterator. It seems like compiler optimizes the code when you use the const _iterator. Is it really correct ? If yes, what really happens internally to make const_iterator takes the edge?. EDIT: I wrote small test to check const_iterator ...