c++

C++, twenty numbers not random?

Why are my C++ numbers not random? #include <iostream> #include <cstdlib> using namespace std; int main() { int randomNumber = rand() % 100; for (randomNumber = 0; randomNumber < 20; randomNumber++) { cout << randomNumber << endl; } return 0; } //Why are my 20 numbers not random? ...

c++ problem with function overloading

Hello, i have a problem with function overloading. I will show you with some simple example: class A {}; class B : public A{}; void somefunction(A&, A&); void somefunction(B&, B&); void someotherfunction() { ... A& a1 = ... A& a2 = ... ... } Both a1 and a2 are instances of B but somefunction(a1,a2); calls void somefunction(A&, ...

c++ publicly inherited class member cannot be used as default argument

A schematic of my problem... class A { public: // etc. protected: uint num; }; class B : public A { public: void foo(uint x = num); //bad }; gives this error: error: invalid use of non-static data member ‘A::num’ error: from this location Why does this happen, and what can I do to work around this? ...

static link library

I am writing a hello world c++ application, in the instruction #include help the compiler or linker to import the c++ library. My " cout << "hello world"; " use a cout in the library. The question is after compile and generated exe is about 96k in size, so what instructions are actually contained in this exe file, does this file also co...

Overloading Output operator for a class template in a namespace.

I've this program #include <iostream> #include <sstream> #include <iterator> #include <vector> #include <algorithm> using namespace std ; #if 0 namespace skg { template <class T> struct Triplet ; } template <class T> ostream& operator<< (ostream& os, const skg::Triplet<T>& p_t) ; #endif namespace skg { template <class T> struc...

How to quickly debug when something wrong in code workflow ?

I have frequently encounter the following debugging scenario: Tester provide some reproduce steps for a bug. And to find out where the problem is, I try to play with these reproduce steps to get the minimum necessary reproduce steps. Sometimes, luckily I found that when do a minor change to the steps, the problem is gone. Then the job ...

Application wide periodic tasks with Dialog Based MFC application

In Single Document Interface (SDI) or Multiple Document Interface (MDI) MFC application, I created an application wide timer in the View. The timer will tick as long as the application is running and trigger some periodic actions. How can I do the same with Dialog Based MFC application? Should I create Thread's Timer (SetTimer with NU...

gcc code::blocks shared library questions

I'm using code::blocks on a linux system with the gcc compiler, and I want to be able to use the shared library template to make a shared library with classes, then make another project that accesses that shared library(at compile time, not dynamically) and classes. I'm sure that code::blocks has simple way of doing this without making c...

How to capture accurate framerate in OpenGL

What is a good way to get an accurate framerate (frames per second) in native windows opengl c++? ...

Is it Bad Practice to use C++ only for the STL containers?

First a little background ... In what follows, I use C,C++ and Java for coding (general) algorithms, not gui's and fancy program's with interfaces, but simple command line algorithms and libraries. I started out learning about programming in Java. I got pretty good with Java and I learned to use the Java containers a lot as they tend t...

C++ compilation for iPhone (STL issue?)

Hello, I am trying to compile some C++ code as a static library to use on the iPhone. If I compile things for the simulator (i386 architecture), everything compiles just peachy, but when I switch the architecture to arm, I get all these include errors, seemingly within the iPhone SDK STL headers. Any idea what's going on? First of the e...

How to find the memory used by any object

class Help { public: Help(); ~Help(); typedef std::set<string> Terms; typedef std::map<string, std::pair<int,Terms> > TermMap; typedef std::multimap<int, string, greater<int> > TermsMap; private: TermMap terms; TermsMap termsMap; }; How can we find the memory used (in bytes...

Boost weak_ptr's in a multi-threaded program to implement a resource pool

I'm thinking of using boost::weak_ptr to implement a pool of objects such that they will get reaped when nobody is using one of the objects. My concern, though, is that it's a multi-threaded environment, and it seems there's a race condition between the last shared_ptr to an object going out of scope and a new shared_ptr being construct...

Is there any charting lib for C++?

I have a C++ program that generates some data and i need to generate some charts for that data and to plot some functions. Is there any free library available that can do that and just generate a png/jpeg(format doesn't matter)? Google charts is not an option as i want to be able to generate charts even when offline. ...

Convert C++ to Python (For Loop multiple assignment)

Convert to python: #include <iostream> using namespace std; int main(int argc, char** argv) { for (int i = 0, j = i + 3; i < 100; ++i, j= i+3) cout << i << " j: " << j << endl; getchar(); return 0; } I try: for i in range(99): j = i + 3 print i, " j: ", j How to make it one for loop? ...

Any smarter way to extract from array of bits?

I have areas of memory that could be considered "array of bits". They are equivalent to unsigned char arr[256]; But it would be better thought of as bit arr[2048]; I'm accessing separate bits from it with #define GETBIT(x,in) ((in)[ ((x)/8) ] & 1<<(7-((x)%8))) but I do it a lot in many places of the code, often in performance-...

How to detect the device name for a capture device?

I am writing a GStreamer application (GStreamer uses DirectShow under the hood on Windows) that captures a computer's microphone and videocamera. It works fine, but requires me to specify the device names manually. I would like to have my program detect these automatically. Does anyone know how to do that? ...

Why can't we declare a std::vector<AbstractClass> ?

Having spent quite some time developping in C#, I noticed that if you declare an abstract class for the purpose of using it as an interface you cannot instantiate a vector of this abstract class to store instances of the children classes. #pragma once #include <iostream> #include <vector> using namespace std; class IFunnyInterface { p...

Programmatically fetch GPU utilization

Is there a standard way of getting the current load on the GPU? I'm looking for something similar to the Task Manager showing CPU%. Utilities such as GPU-Z show this value but I'm not sure how it gets this. I'm specifically interested in AMD graphics cards at the moment, any pointers would be helpful. If there's no clean API way of do...

Restricting the size of an array when passed to a function

Is there anyway to restrict the size of an array when passed as an argument to a function? I mean is something like this possible? /*following will lead to compile time error */ template<typename T, size_t n>=20> // or template<typename T,size_t n<=20> void func(T (&a)[n]) { // do something with a } I want the size of my array t...