c++

One function for addition/subtraction in "Clock arithmetic"/congruent math?

Hi, I want to "mix" char* data in this form: source = (source + some_primary_number) % 256; --the 256 line is because of I need to keep the range of char. so I can do the "mix" and "un-mix" in 2 functions - the implementation above is for the mixing and this one is for the un-mixing: source = source - some_primary_number; if ( so...

Definitive function for get elapsed time in miliseconds

I have tried clock_gettime(CLOCK_REALTIME) and gettimeofday() without luck - And the most basic like clock(), what return 0 to me (?). But none of they count the time under sleep. I don't need a high resolution timer, but I need something for getting the elapsed time in ms. Thanks. EDIT: Final program: #include <iostream> #include <...

question on string in c++

does this work on string in c++? string s="lomi"; cout<<s<<endl; what is bad in this code? #include <iostream> #include <cstring> using namespace std; int main(){ string s=string("lomi"); for (int i=0;i<s.length();i++){ s[i]= s[i]+3; } std::cout<<s<<std::endl; return 0; } ? ...

Qt programming: More productive in Python or C++?

Trying to dive into Qt big time but haven't done a large project with it yet. Currently using Python, but I've been thinking -- which is really the better language to use in terms of programmer productivity? In most comparisons between the languages, Python is the obvious answer, because you don't have to mess with memory management and...

Is there any Tables lib/code for in memory manipulation in C++

I've started doing my own "struct of arrays" coding, but wondered if anyone knew of libs or templates that were already out there for doing intense data transform stuff on memory constrained hardware. I suppose what I'm looking for is a sort of "in memory" container that allows me to queue up insertions until a sync point, and mid itera...

Scope of pure virtual functions during derived class destruction - In C++

Hi, During destruction of the derived class object, i first hit the derived class destructor and then the base class destructor (which is as expected). But i was curious to find out - at what point does the functions of the derived class go out of scope (are destroyed). Does it happen as soon as the control leaves the derived class des...

How to I represent a '<' character in my XML documentation?

I've seen various questions here on SO involving Microsoft's XML documentation tags, but I'm having trouble adding some example code: /// <summary>Return the oldest acceptable timestamp for a data packet.</summary> /// <example> /// if( GetOldestValidResultTime() < lastResultTime ) /// { /// Console::WriteLine("Results are too old")...

Simple C++ Writing to File: Nothing Gets Written! Should be easy, but I'm stumpted.

Thank you so much for helping me! Everyone is so fast and excellent! Thanks again! What is happening is no data is being written to my file, after I test this code. Just a 0 appears. What am I doing wrong? void CreateHtmlFile(string myMessages[]) { int i = 0; int emptyarray = 0; int myEmptyCounter = 0; int emptyArrayCounter = ...

How to refactor an existing class to become polymorphic?

I have a class that is used as a member in many places in my project. Now, instead of this class I want to have a polymorphism, and the actual object will be created by some kind of factory. I have to choose between: Having to change all the places where I use the class - to call the factory and use a pointer instead of object directl...

Simple simple template returning odd numbers?

EDIT BEFORE YOU READ: Sorry.. I didn't add newline so it appeared jumbled, I can't delete the question because I'm not registered yet, sorry for wasting your time guys. I just used a template for the first time (for finding MIN of two numbers) instead of a macro, and I liked it! But when I tried to modify and make my own template it fai...

Windows 7 x64: low IL process msdn example does not work

Hello I want to create process with low integrity level from process with medium integrity level. I found msdn example: Designing Applications to Run at a Low Integrity Level But it does not work on my system. Process is created successfully, but message box "Alpplication failed to initialized properly(0xC0000022 -- STATUS_ACCESS_DE...

Fixing "comparison is always false ..." warning in GCC.

I'm having a problem which I'm sure is simple to fix but I'm at a loss... I have a template that performs the following code: T value = d; if ( std::numeric_limits< T >::is_signed ) { if ( value < 0 ) { *this += _T( "-" ); value = -(signed)value; } } Now for, obvious reasons, GCC is giving me a warning...

Test for overhead of virtual functions

I set up a (perhaps very unscientific) small test to determine the overhead of virtual functions in a one-level single inheritance and the results I got were, well, exactly the same when accessing the derived class polymorphically or when accessing it directly. What was a bit surprising was the order of magnitude of computation time that...

Is the padding between class members of the same type always the same?

The following class contains some members of the same type: template <typename T> class MyClass { T m0; T m1; T m2; T m3; T m4; //... }; The members are all declared without an intervening access-specifier and thus are allocated that later members have higher addresses (ISO/IEC 14882: 9.2.12). The same paragrap...

When is (this != this) in C++ !?

I have a very strange question. I have a class/function : class MCBSystem { [...] template <class Receiver> void setCallBack(int i, Receiver* receiver, void(Receiver::*function)(void*)) { iCallBacks.at(i) = new CallBack<Receiver>(receiver, function, this); }; }; And I inherit it (multiply) in another class :...

Any performance reason to put attributes protected/private ?

I "learned" C++ at school, but there are several things I don't know, like where or what a compiler can optimize, seems I already know that inline and const can boost a little... If performance is an important thing (gaming programming for example), does putting class attributes not public (private or protected) allow the compiler to ma...

Difference between Dynamic Loading VS Reduce Number of subclassing in Prototype

AFAIK, reduce the number of sub classing means you don't actually code the class statically but you create the object with different properties in order to avoid create many subclass. class carPrototype : public prototype { prototype* clone(); }; Yon doesn't require to create a class called sedanCarPrototype, superCarPrototype but j...

What is purpose of _p.h files?

In Qt Source files, there are two versions of header files, such as: qxmlstream.h qxmlstream_p.h Why are there _p.h files? ...

pthread_setschedprio() fails with "EINVAL"

I just started with pthreads and don't know much about it. I was trying to set the priorities of pthreads using pthread_setschedprio() but it returns "EINVAL". Here is my code: #include <pthread.h> #include <errno.h> void *Run(void *ptr); class Thread { public: pthread_t myPthread; void start() { pthread_create( &myP...

what is a good alternative to this ugly construct, in c++?

This is my code (simplification of a real-life problem): class Foo { public: void f(const string& s) { if (s == "lt") { return lt(); } else if (s == "lte") return lte(); } else if (s == "gt") return gt(); } else if (s == "gte") return gte(); } } void lt() { /* skipped */ } void lte() {...