c++

Finding the end of a zlib compressed stream

I'm working on an NMDC client (p2p, DC++ and friends) with Qt. The protocol itself is pretty straightforward: $command parameters| Except for compression: "ZPipe works by sending a command $ZOn| to the client. After $ZOn a ZLib compressed stream containing commands will follow. This stream will end with an EOF that ZLib defines. ...

NOT sharing all classes with shared library

As ugly as win32 Microsoft compiler is by using the __declspec macro, it does have the advantage of being explicit about what you want to export or not. Moving the same code onto a Linux gnu/gcc system now means all classes are exported!(?) Is this really true? Is there a way to NOT export a class within a shared library under gcc? #...

Why is my Breakpoint Condition not being met when my Breakpoint Condition is being met in Visual Studio?

I have a piece of code in front of me that iterates through a long list of urls and something is going wrong when those urls include a certain type of document. I don't want to see every iteration, so I've set up a conditional breakpoint. The trouble is that I'm not a C++ programmer so I'm slightly having to fish around to work out how ...

Issues when moving code from one class into a new class?

I had some decryption code (using wincrypt.h) that lived within my FileReader.cpp class. I am trying to segregate the code and push this decryption method into a MyCrypt.cpp class. However, upon moving it I'm stuck with a bunch of errors that I wasn't facing before. For every wincrypt.h or windows.h specific command, I am recieving "i...

boost random number library, use same random number generator for different variate generators

It seems that one can use the following code to produce random numbers from a particular Normal distribution: float mean = 0, variance = 1; boost::mt19937 randgen(static_cast<unsigned int>(std::time(0))); boost::normal_distribution<float> noise(mean, variance); variate_generator<mt19937, normal_distribution<float> > nD(randgen, noise); ...

PIMPL problem: How to have multiple interfaces to the impl w/o code duplication

I have this pimpl design where the implementation classes are polymorphic but the interfaces are supposed to just contain a pointer, making them polymorphic somewhat defeats the purpose of the design. So I create my Impl and Intf base classes to provide reference counting. And then the user can create their implementations. An example: ...

C++ - calling methods from outside the class

I have couple questions regarding some C++ rules. Why am I able to call a function/method from outside the class in the namespace when I include the return type? (look at the namespace test2::testclass2 in the code below) i.e. this works: bool b = testclass1::foo<int>(2); whereas this doesn't: - (it doesn't even compile - compiler t...

Function for perspective projection of a matrix in C++

Hi, Does anyone have a function that returns the perspective projection of a 3x3 matrix in C++? Matrix Perspective() { Matrix m(0, 0, 0); // Creates identity matrix // Perspective projection formulas here return m; } ...

When should functions be member functions?

I have a colleague in my company who's opinions I have a great deal of respect for, but I simply cannot understand one of his preferred styles of writing code in C++. For example, given there is some class A, he'll write global functions of the type: void foo( A *ptrToA ){} or: void bar( const A &refToA ){} My first instinct upon ...

Given an angle and length, how do I calculate the coordinates

Assuming the upper left corner is (0,0) and I'm given an angle of 30 degrees, a starting point of (0,300), a line length of 600, how do I calculate the ending point of the line so that the line is representative of the angle given. The C pseudo-code is main() { int x,y; getEndPoint(30, 600, 0, 300, &x, &y); printf("end x=%d, en...

C++ stack allocated object, explicit destructor call

Hi, I came across a strange use of the destructor while working on an existing library. The destructor of a stack allocated stl vector was being called explicitly, when its the case that that object may need to be used again. These vector objects are a slightly customised version of the stl vector class that have a specialized clear met...

show/hide desktop icons from c++ application

Right-click on desktop, uncheck view->Show Desktop icons. All icons on desktop will disappear. Is it possible to show/hide desktop icons from c++ application? Do you have an example of c++ code for it? Thanks a lot in advance for any suggestions. ...

Cannot load SQL driver in Visual C++ (but loads in QtCreator)

I have a QT application that requires the MySql driver. I have both a .pro file to compile the app with QtCreator and a .vcproj for Visual C++ 2008 Express. The code is identical and it compiles without a hitch, but the executable created by Visual C++ Express gives me the following output and refuses to load any driver/plugin: QSqlData...

How can I truncate the mangled C++ identifiers shown by GDB's disassemble command?

GDB's disassemble command is nice for short C identifiers, e.g. main. For long, mangled C++ identifiers the verbosity is overkill. For example, using icpc I see results like (gdb) disassemble 0x49de2f 0x49de5b Dump of assembler code from 0x49de2f to 0x49de5b: 0x000000000049de2f <_ZN5pecos8suzerain16fftw_multi_array6detail18c2c_buffer_p...

How to declare a static const char* in your header file?

I'd like to define a constant char* in my header file for my .cpp file to use. So I've tried this: private: static const char *SOMETHING = "sommething"; Which brings me with the following compiler error: error C2864: 'SomeClass::SOMETHING' : only static const integral data members can be initialized within a class I'm...

Boost Asio async_read doesn't stop reading?

So, I've been playing around with the Boost asio functions and sockets (specifically the async read/write). Now, I thought that boost::asio::async_read only called the handler when a new buffer came in from the network connection... however it doesn't stop reading the same buffer and thus keeps calling the handler. I've been able to m...

32 bit pointer in a 64 bit Solaris compile.

I know this is a strange questions but I was wondering if it was possible to make a 32 bit pointer in 64 bit compile on Solaris using g++. The final object would need to be 64 bit however one of my pointers offsets is becomming larger on Solaris then it is in windows if I do use 64 bit to compile. This is causing a big problem. I was ...

How do I use member functions of constant arrays in C++?

Here is a simplified version of what I have (not working): prog.h: ... const string c_strExample1 = "ex1"; const string c_strExample2 = "ex2"; const string c_astrExamples[] = {c_strExample1, c_strExample2}; ... prog.cpp: ... int main() { int nLength = c_astrExamples.length(); for (int i = 0; i < nLength; i++) cout << c_...

Comparing character arrays and string literals in C++

I have a character array and I'm trying to figure out if it matches a string literal, for example: char value[] = "yes"; if(value == "yes") { \\ code block } else { \\ code block } This resulted in the following error: comparison with string literal results in unspecified behaviour. I also tried something like: char value[] = "...

Best way to setup a Windows build environment for C/C++

Basically I want to compile C/C++ using the GCC on Windows. The two competing platforms, as i see it, are MinGW and Cygwin. Each have their own benifits and limitations. MinGW compiles for Windows, whereas Cygwin needs the cygwin .dll. However installing libraries on MinGW is difficult, whereas on cygwin it's easier, using the setup.exe ...