c++

How to change implementation of returned object base class's function when object is returned C++

I have an existing application in C++ with a custom ArrayBase class that manages storage and access to a contiguously allocated region of memory. I have a separate ItrBase class that is used to access data in that ArrayBase. ArrayBase has a createItr() function that currently returns an ItrBase object. I need to extend ArrayBase to us...

C++: error "explicit specialization in non-namespace scope"

template<typename T1, typename T2> class Bimap { public: class Data { private: template<typename T> Data& set(T); template<> Data& set<T1>(typename T1 v) { /*...*/ } }; }; That gives me the error: error: explicit specialization in non-namespace scope 'class Bimap<T1, T2>::Data' I understand what the error ...

using map erase - Deleting from a map which contains pointer to another map

when i try to remove an element: i go to secondMap which contains in second field a pointer to the first map, now when i try to erase it it gives me problems: multimap<SortKey,T> firstMap; multimap<SearchKey,pair<const SortKey,T>*> secondMap; template <class T,class SortKey, class SearchKey> T GarageDataBase<T,SortKey,SearchKey>::...

how to Override operator <

I'm trying to override operator < as the following : inside Node : bool operator <(const Node* other) { return *(this->GetData()) < *(other->GetData()); } inside vehicle : bool operator <(const Vehicle &other) { return this->GetKilometersLeft() < other.GetKilometersLeft(); } invoking the operator : while (index > 0 && m_he...

Why am I getting this redefinition of class error?

Apologies for the code dump: gameObject.cpp: #include "gameObject.h" class gameObject { private: int x; int y; public: gameObject() { x = 0; y = 0; } gameObject(int inx, int iny) { x = inx; y = iny; } ~gameObject() { // } int add() { retur...

OpenGL ARB function in Mac

I want to use glCurrentPaletteMatrixARB in Mac application. OpenGL library is imported GLEW library and GLUT and, glewInit() function calling was successful. glWeightPointerARB function is able to call, but my application crashed in glCurrentPaletteMatrixARB. Reason is function pointer value is null pointer error. Extension string is no...

Local class template

We can have a local class defined inside a function but this class cannot be a template which is bit annoying and inconsistent. Is there any update on that in C++0x standard? ...

C++ pass by pointer

hello, guys, i am very new to c++. i have just wrote this class: class planet { public: float angularSpeed; float angle; }; here is a function trying to modify the angle of the object: void foo(planet* p) { p->angle = p->angle + p->angularSpeed; } planet* bar = new planet(); bar->angularSpeed=1; bar->angle=2; foo(bar); It seem t...

C++ Game - Signalling a parent class, circular dependency issue

I'm having a little circular-dependency problem. It works fine, but it makes for ugly-seeming code. It's in the context of a Snake game. I have a class, Snake, which contains a vector of SnakeSegments, and manages their interaction (for instance moving and growing as a unit, rather than as separate entities). When a SnakeSegment collid...

concurrent queue in C++

I am trying to design a queue which could be simultaneously accessed by multiple read/write threads. I prefer using 2 mutexes, one apiece for read and write. Doing write is simple enough, lock the write mutex, append data, unlock and you are done. The issue is with read. If there's no data in the in queue I'd like my thread to wait til...

C++: using function pointers as template arguments

I have the following code: template<typename Parent, typename T, void (Parent::*Setter)(T), T (Parent::*Getter)()> struct Property { Parent& obj; Property(Parent& _obj) : obj(_obj) {} Property& operator=(T v) { (obj.*Setter)(v); return *this; } operator T() { return (obj.*Getter)(); } }; template<typename T1, typename T2> class Bim...

trying to count instances of deriving classes, type_id doesnt work

first of all i think its a crapy design , but im trying to prove a point. i want to count all the instances of derivers from my class, im trying to do it like so: .h file: #ifndef _Parant #define _Parant #include<map> class Parant { public: Parant(); virtual ~Parant(); static void PrintInstances(); private: static v...

How I can do an event in c++?

Well, sorry if my english isn't very good, second, in c++ how i can make events?, is something that i can't find as much i searched, and i think that it could help me a lot to make me the things a little easier with the college. Thanks for your answers. ...

copy smaller array into larger array

I have two arrays of chars, allocated as follows: unsigned char *arr1 = (unsigned char *)malloc((1024*1024) * sizeof(char)); unsigned char *arr2 = (unsigned char *)malloc((768*768) * sizeof(char)); I would like to copy arr2 into arr1, but preserve the row/column structure. This means that only the first 768 bytes of each of the fir...

why use virtual destructor in inheritance

Possible Duplicate: When to use virtual destructors? let's say i have an abstract class Animal class Animal { public: Animal(const std::string &name) : _name(name) { } virtual void Print() const = 0; virtual ~Animal() {} protected: std::string _name; }; and i have Dog and Cat that inherit this class....

Initializing 2 dimensional array of structs in C++

Hi, I am trying to initialize a 2D array of structs in C++, but am getting an error. Can someone please tell me what am I doing wrong? I have rechecked the braces and they seem to be fine. My code: struct CornerRotationInfo { bool does_breed; int breed_slope; bool self_inversion; int self_slope; inline CornerRotationInfo(b...

Put in the KDE SystemTray in the QT

Hi I'm designing an application platform and want to integrate Linux in particular for the KDE desktop only independent bookstores that if I use KDE and the QT libraries the look and feeling not like and I have all the power of the KDE libraries. The problem is, I want to be an application platform that includes the libraries to compile...

Is there some website that have examples of every methods in the python standard library?

For example, c++ have cplusplus.com/reference which contain all of c++ standard library complete with definitions and more importantly examples, so I was wondering if there is such a website for python. I know that python is self documented, like i could use help(object) object.__doc__ dir(object) I know of doc.python.org/library w...

Changing the current directory in Linux using C++

I have the following code: #include <iostream> #include <string> #include <unistd.h> using namespace std; int main() { // Variables string sDirectory; // Ask the user for a directory to move into cout << "Please enter a directory..." << endl; cin >> sDirectory; cin.get(); // Navigate to the directory spec...

How to use named mutex and shared memory between a windows service and a process ?

Hello all, I'm have a code written in C++\MFC that is run as a Windows Service and a (normal) C++\MFC Windows process - now I wish to communicate between the two using named Mutex and Shared memory (File mapping). How is that possible ? ...