c++

Qt::How to lower the text in a qspinbox

I'm using a spinbox with a custom font which looks too high in the spinbox. How do I move the text lower? I have already reimplemented Qstyle and made the font lower in another widget but I can't find where to do it with the spinbox, there must be a qrect somewhere where you can just move the top of it but I don't know and can't seem to ...

Qt4: QMap causing "strict-aliasing rules" compilation error

I'm trying to create the following data structure in Qt 4.5 in C++: QMap<int, QMap<QString, QVector<QPointF> > > animation; However, the inclusion of this line in my code results in the following error: cc1plus: warnings being treated as errors In file included from XXX/XXX/XXX/MainWindow.qt.C.tmp.C:113: /usr/lib/qt4/include/QtCore/q...

new returns NULL when initializing static global variable in windows?

I'm working on integrating rLog with our code base, and I'm noticing a problem on Windows that I don't have on linux. In a header file I have a static variable that gives me a "verbose" logging channel (one up from debug basically), defined thusly: static RLogChannel *rlog_verbose = DEF_CHANNEL("verbose", Log_Debug); There's no probl...

using setw with user-defined ostream operators

How do I make setw or something similar (boost format?) work with my user-defined ostream operators? setw only applies to the next element pushed to the stream. For example: cout << " approx: " << setw(10) << myX; where myX is of type X, and I have my own ostream& operator<<(ostream& os, const X &g) { return os << "(" << g.a...

Can I return in void function?

I have to return to the previous level of the recursion. is the syntax like below right? void f() { // some code here // return; } ...

how do I make a portable isnan/isinf function.

I've been using isinf,isnan functions on linux platforms which worked perfectly. But this didn't work on osx, so I decided to use std::isinf std::isnan which works on both linux and osx. But the intel compiler doesn't recognize it, and I guess its a bug in the intel compiler according to http://software.intel.com/en-us/forums/showthread...

Help with vectors

I'm trying to make a game where the bullets can fly in any direction. I would ike to make them vectors with a direction and magnitude to make them go the direction. I'm just not sure how to implement this? Thanks ...

Template / Namespace Interactions

I came across a compile.. oddity? recently that led me to believe that a template, when created, is created in the same namespaces (or, at least, using the same namespaces) as where is was declared. That is; template<class T> class bar { public: static int stuff(){return T::stuff();} }; namespace ONE { struct foo { ...

A few questions about C++ classes.

I have two basic questions. The first one is about function in other classes. If I have a header file with a class in it and I want to use that function in another class I have created, do I always have to construct a class object to run a function in that class like: someclass class; <----object construction class.somefunction(); ...

C / C++ : Portable way to detect debug / release ?

Is there a standardized (e.g. implemented by all major compilers) #define that will allow me to distinguish between debug and release builds? ...

New .h file in Eclipse yields a #define constant

So I'm chugging along in learning C++ and I'm starting to use Eclipse. As I create my .h files, I get this strange #define constant at the top: #ifndef CLASSNAME_H_ #define CLASSNAME_H_ #endif /* CLASSNAME_H_ */ So, what gives? Am I supposed to use CLASSNAME_H_ for something? (I should note that "classname" is just a filler. So, fo...

C++ Sample Project - Need help with algorithm

Hello! I had one of my friends send me this programming assignment so I could brush up on some of my C++ skills. Below is the program description and my proposed algorithm. Could someone please provide some feedback/alternative solutions: Problem: This program creates word search puzzles - Words are printed at random locations in a rec...

Acquire a lock on two mutexes and avoid deadlock

The following code contains a potential deadlock, but seems to be necessary: to safely copy data to one container from another, both containers must be locked to prevent changes from occurring in another thread. void foo::copy(const foo & rhs) { pMutex->lock(); rhs.pMutex->lock(); // do copy } Foo has an STL container and ...

c++ transform with if_then_else control structure

I'm trying to change the integer values in a vector using transform and an if_then_else control structure from Boost Lambda. However my compiler is not appreciating my efforts. The code I am attempting is: transform(theVec.begin(), theVec.end(), theVec.begin(), if_then_else(bind(rand) % ratio == 0, _1 = bind(rand) % maxSize, ...

How to use the boost lexical_cast library for just for checking input

I use the boost lexical_cast library for parsing text data into numeric values quite often. In several situations however, I only need to check if values are numeric; I don't actually need or use the conversion. So, I was thinking about writing a simple function to test if a string is a double: template<typename T> bool is_double(cons...

How to design a class where the user/caller has options to provide a custom behavior using a custom class

I encounters a problem where I want to have a class in which its behavior can be customized by another class, for example, Foo's constructor accepts a parameter of some type of class: class Bar { //The default class that define behavior }; template <typename T = Bar> class Foo { public: Foo(T* t = 0) t_(t) { if (t_ == 0) t_...

How to make a Yahoo 10 IM Auto Reply program in C++?

How to make a Yahoo Auto Reply program in C++? ...

C++: Problem using std::cout with gcc on a mac osx

Hi I'm new to C++ programming and I try to make my first exercise on a mac using gcc in the terminal. Unfortunately, I can't compile because of issues related to iostream. With a simple program as : #include "<"iostream">" int main() { std::cout << "hello world"; std::cout << endl; return 0; } it gives me the error: error: ‘en...

Interpretation of int (*a)[3]

When working with arrays and pointers in C, one quickly discovers that they are by no means equivalent although it might seem so at a first glance. I know about the differences in L-values and R-values. Still, recently I tried to find out the type of a pointer that I could use in conjunction with a two-dimensional array, i.e. int foo[2]...

[C++] Getting undefined class type error but I did create the class and defined it

Hi. Im working on an assignment for one of my classes. Simply I have a GumballMachine class and a bunch of State classes that change the state of the GumballMachine. Here is the offending code: class GumballMachine; class State { public: virtual void insertQuarter() const = 0; virtual void ejectQuarter() const = 0; virtual void tur...