c++

How to use windows socket to find: number of bytes in output buffer pending send, but not yet transfer onto wire?

I already did a bit of research & tried a few things... but still can't find how to programmatic detect if there are any bytes (that maybe already be awaiting inside the outgoing queue) which had not been transmitted to the cable. Thanks ...

How to write comparator function for qsort?

class for example: class classname{ public: int N,M; }; classname a > classname b if a.N>B.N ...

C++ member layout

Hello! Let's we have a simple structure (POD). struct xyz { float x, y, z; }; May I assume that following code is OK? May I assume there is no any gaps? What the standard says? Is it true for PODs? Is it true for classes? xyz v; float* p = &v.x; p[0] = 1.0f; p[1] = 2.0f; // Is it ok? p[2] = 3.0f; // Is it ok? ...

Stripping linux shared libraries

We've recently been asked to ship a Linux version of one of our libraries, previously we've developed under Linux and shipped for Windows where deploying libraries is generally a lot easier. The problem we've hit upon is in stripping the exported symbols down to only those in the exposed interface. There are three good reasons for wantin...

How do I find the cause of this linker error?

After going through a lengthy process to rename a project, my DLL project will not build in Debug mode (Release builds work): MSVCRTD.lib(msvcr90d.dll) : error LNK2005: _CrtDbgReportW already defined in LIBCMTD.lib(dbgrpt.obj) This project, and the five static libraries it depends on, are set to use "Multi-threaded Debug (/MTd)" (unde...

C++ checking the type of reference

Hi Is it bad design to check if an object is of a particular type by having some sort of ID data member in it? class A { private: bool isStub; public: A(bool isStubVal):isStub(isStubVal){} bool isStub(){return isStub;} }; class A1:public A { public: A1():A(false){} }; class AStub:public A { public: AStub():A(true){} }; E...

how to remove all even integers from set<int> in c++

I'm new to C++. I'd like to know how experienced coders do this. what I have: set<int> s; s.insert(1); s.insert(2); s.insert(3); s.insert(4); s.insert(5); for(set<int>::iterator itr = s.begin(); itr != s.end(); ++itr){ if (!(*itr % 2)) s.erase(itr); } and of course, it doesn't work. because itr is incremented after it is erased....

Manually drawing gradients for buttons, toolbars, tabs etc?

I would like to update some toolbar-like code we have to have a Vista/Win7 gradient roundedness to them. Currently, the buttons have the Windows 2000 look & feel: blocky, single-tone. I've played around with the XP themes, and using DrawThemeBackground, DrawThemeEdge, etc.; but I'm very dissatisfied with the theme drawing mechanics (th...

Using USB port from c++

Hello, i was just wondering if somebody could give me any pointers about how to use USB ports on Ubuntu(and other unix systems) &&/|| (and/or :]) windows. I was trying to googling some stuff up but i failed horribly. Even names of libraries to be used etc would be appriciated. Thanks, Tomas Herman ...

How do you use the non-default constructor for a member?

I have two classes class a { public: a(int i); }; class b { public: b(); //Gives me an error here, because it tries to find constructor a::a() a aInstance; } How can I get it so that aInstance is instantiated with a(int i) instead of trying to search for a default constructor? Basically, I want to con...

What is correct way to initialize a static member of type 'T &' in a templated class?

I'm playing around with an eager-initializing generic singleton class. The idea is that you inherit publicly from the class like so: class foo : public singleton<foo> { }; I've learned a lot in the process but I'm stuck right now because it's breaking my Visual Studio 2008 linker. The problem is with the static instance member and/or ...

cyclic dependency between header files

I'm trying to implement a tree-like structure with two classes: Tree and Node. The problem is that from each class I want to call a function of the other class, so simple forward declarations are not enough. Let's see an example: Tree.h: #ifndef TREE_20100118 #define TREE_20100118 #include <vector> #include "Node.h" class Tree { ...

HornetQ Client in C++ which supports security?

Is there a SSL enabled client for C++ that can interact with HornetQ? The only client I could find is ActiveMQ-CMS from the Apache ActiveMQ project, which can use Stomp. But this client up to now does not seam to support SSL or any other form of security/authentication. ...

pure virtual function with implementation

Hi, My basic understanding is that there is no implementation for a pure virtual function, however, I was told there might be implementation for pure virtual function. class A { virtual void f() = 0; }; void A::f() { cout<<"Test"<<endl; } Is code above OK? What's the purpose to make it a pure virtual function with an implementa...

Guides, Tutorials or Books about building MacOSX GUI apps with C++ in Xcode?

Hi, with GUI apps I mean not just a Unix command line application, but the whole .app bundle and a full Cocoa or Carbon application. Thanks! PS: I wasn't totally accurate with GUI application. I meant an application with a window and a menu, as opposed to a Unix command line application. Actually I got to a tutorial about programming wi...

Is ACE reactor timer managment thread safe?

I have a module that manages timers in my aplication. This class has basibly three functions: Instance of ACE_Reactor is used internally by the module to manage the timers. schedule timer - calls ACE_Reactor::schedule_timer(). One of the arguments is a callback, called upon timer experation. cancel timer - calls ACE_Reactor::cancel_t...

Identifying a C# or C++ function start in a line count program

I have a program, written in C#, that when given a C++ or C# file, counts the lines in the file, counts how many are in comments and in designer-generated code blocks. I want to add the ability to count how many functions are in the file and how many lines are in those functions. I can't quite figure out how to determine whether a line (...

How to get TRUE hardware MAC address

I know, that this question was created many times, but it is stil open The problem is following: My application need to generate some UID for computer, it working on. I need it to implement the genuine protection. MAC address is a good candidate, because it is unique for each ethernet card. Many articles uses either GetAdaptersInfo, ...

Using operator+ without leaking memory?

So the code in question is this: const String String::operator+ (const String& rhs) { String tmp; tmp.Set(this->mString); tmp.Append(rhs.mString); return tmp; } This of course places the String on the stack and it gets removed and returns garbage. And placing it on the heap would leak memory. So how shoul...

Magic Numbers In Arrays? - C++

Hi there, I'm a fairly new programmer, and I apologize if this information is easily available out there, I just haven't been able to find it yet. Here's my question: Is is considered magic numbers when you use a literal number to access a specific element of an array? For example: arrayOfNumbers[6] // Is six a magic number in this...