c++

Efficiently allocating many short-lived small objects

I've got a small class (16 bytes on a 32bit system) which I need to dynamically allocate. In most cases the life-time of any given instance is very short. Some instances may also be passed across thread boundaries. Having done some profiling, I found that my program appears to be spending more time allocating and deallocating the things...

Evolution of Class

Was class evolve from structures? ...

Bizarre thread printing behaviour

Hey - I'm having an odd problem with a little toy program I've written, to try out threads. This is my code: #include <pthread.h> #include <iostream> using std::cout; using std::endl; void *threadFunc(void *arg) { cout << "I am a thread. Hear me roar." << endl; pthread_exit(NULL); } int main() { cout << "Hello there." <<...

How do I wrap CFtpFileFind example, in C++?

Trying to wrap this short example in C++. (and its been a while since I did this). int main(int argc, char* argv[]) { //Objects CFtpConnection* pConnect = NULL; //A pointer to a CFtpConnection object ftpClient UploadExe; //ftpClient object pConnect = UploadExe.Connect(); UploadExe.GetFiles(pConnect); ...

Does protected inheritance allow the derived class access the private members of its base class?

Hi, I am really confused about private inheritance and protected inheritance. 1) in protected inheritance, the public and protected members become protected members in the derived class. In the private inheritance, everything is private. However, the derived class can never access the private members of the base class, is that right? ...

Directed graph implementation

I need to implement a digraph(Directed graph) in c++ as part of a homework and i'm having some issues with how to represent the vertices and edges data types. Can anybody please point me to a example or a simple c++ class that implements this so i can study it and extend from there? I've googled for a bit but i only found results abou...

Compilation error - no matching function for call to 'Exception::Exception(Exception)'

Hello. I can not solve this problem for a while. I would be glad for some advice. When I try to throw an exception (self created one in Java style) throw Exception (); compiler make a protest: DataTypes/Date.cpp:24: error: no matching function for call to `Exception::Exception(Exception)' DataTypes/Date.cpp:24: error: in thr...

What does it mean when a variable appears red in the visual studio C++ debugger?

what does it mean when a variable appears red in the visual studio C++ debugger? I assume not good. Thanks. ...

C++ pointer multi-inheritance fun.

I'm writing some code involving inheritance from a basic ref-counting pointer class; and some intricacies of C++ popped up. I've reduced it as follows: Suppose I have: class A{}; class B{}; class C: public A, public B {}; C c; C* pc = &c; B* pb = &c; A* pa = &c; // does pa point to a valid A object? // does pb point to a valid B obje...

Runtime typeswitch for typelists as a switch instead of a nested if's ?

This is from TTL: //////////////////////////////////////////////////////////// // run-time type switch template <typename L, int N = 0, bool Stop=(N==length<L>::value) > struct type_switch; template <typename L, int N, bool Stop> struct type_switch { template< typename F > void operator()( size_t i, F& f ) { ...

C++ template for generating parts of switch statement?

Is it possible to write a template Foo<int n> such that: Foo<2> gives switch(x) { case 1: return 1; break; case 2: return 4; break; } while Foo<3> gives switch(x) { case 1: return 1; break; case 2: return 4; break; case 3: return 9; break; } ? Thanks! EDIT: changed code above to return square, as many have gue...

Whats the difference between C++ and C++ CLI

I'm learning C++ (CLI apparently), and every time I post a question saying that I am using C++, someone jumps down my throat saying that I'm not using C++, but C++/CLI. I'm not really sure of a difference, as I am extreamely new to this, but it seems to make everyone upset. Can anyone shine some light on the differences? As a second n...

what is the error in my program??

Hello, I am trying to intercept libpthred( POSIX ) function calls using LD_PRELOAD technique. First I tried to create my own shared library having the same functin names as in the pthread library. Here is an example of my own created pthread_create function which first gets the address of original pthread_create function in the pthread l...

[GTK+] Change progress bar with circular wait image

Hi, Is it possible to skin the GTK+ progress bar widget such that it shows a custom image (an AJAX style animated gif maybe)? If so how and if not, is there any other option/control which can achieve this effect? ...

Using 'const' in class's functions

I've seen a lot of uses of the const keyword put after functions in classes, so i wanted to know what was it about. I read up smth at here: http://duramecho.com/ComputerInformation/WhyHowCppConst.html . It says that const is used because the function "can attempt to alter any member variables in the object" . If this is true, then shoul...

const cast to allow read lock, does this smell bad ?

I want to execute a read-only method on an object marked as const, but in order to do this thread-safely, I need to lock a readers-writer mutex: const Value Object::list() const { ScopedRead lock(children_); ... } But this breaks because the compiler complains about "children_" being const and such. I went up to the ScopedRead cla...

about throw() in C++

void MyFunction(int i) throw(); it just tells the compiler that the function does not throw any exceptions. It can't make sure the function throw nothing, is that right? So what's the use of throw() Is it redundant? Why this idea is proposed? ...

Reading/Writing integer values on a string object

Hi, I have the contents of a file assigned into a string object. For simplicity the file only has 5 bytes, which is the size of 1 integer plus another byte. What I want to do is get the first four bytes of the string object and somehow store it into a valid integer variable by the program. Then the program will do various operations on ...

Linking static libraries to other static libraries

I have a small piece of code that depends on many static libraries (a_1-a_n). I'd like to package up that code in a static library and make it available to other people. My static library, lets call it X, compiles fine. I've created a simple sample program that uses a function from X, but when I try to link it to X, I get many errors...

virtual function in private or protected inheritance

Hi, It's easy to understand the virtual function in public inheritance. So what's the point for virtual function in private or protected inheritance? For example: class Base { public: virtual void f() { cout<<"Base::f()"<<endl;} }; class Derived: private Base { public: void f() { cout<<"Derived::f()"<<endl;} }; Is this still cal...