c++

C++ game, class design and responsibilities

I've just read some related questions that came up when I typed the subject, so I'll try not to repeat those. I've recently started revisiting a learning project I started about two or three years ago - a C++ port of a Mega Man engine. Yes I used ripped sprites. I also am using a game engine library for drawing, music, and input. My or...

How can I multiply matrix greater than 4 x 4 in the vc++ using directx?

I have to multiply 12x12 matrix with 12x 1 matrix in VC++ directx. Which template library should I use with vs 2005 I want to do matrix multiplication faster too. ...

what are the fast algorithms to find duplicate elements in a collection and group them?

Say you have a collection of elements, how can you pick out those with duplicates and put them into each group with least amount of comparison? preferably in C++, but algorithm is more important than the language. For Example given {E1,E2,E3,E4,E4,E2,E6,E4,E3}, I wish to extract out {E2,E2}, {E3,E3}, {E4,E4,E4}. what data structure and...

How to serialize derived template classes with Boost.serialize?

Hello! I'd like to serialize/unserialize following classes: class Feature{ ... virtual string str()=0; }; template<typename T> class GenericFeature : public Feature{ T value; ... virtual string str(); }; I read boost.serialize docs and the sayed that you must register classes. I can register them in constructor. But there will be p...

defining bunch of static methods in c++

Which is appropriate: class xyz { static int xyzOp1() { } static int xyzOp2() { } }; OR namespace xyz { static int xyzOp1() {} static int xyzOp2() {} }; Is there something specific which we can get when we define using class tag in comparision with namespace tag? Also is there any different in memory management, which we n...

Most Common Memory/Resource Leak Errors.

All good C++ programmers know how to avoid leaking memory (or resources like sockets): Always use smart pointers, i. e.: std::auto_ptr, boost::shared_ptr. Always be aware of ownership of object: who owns, who refers, who is responsible, etc. But, memory leaks still happen. Point most common issues when you discovered a memory leak i...

Priority when choosing overloaded template functions in C++

I have the following problem: class Base { }; class Derived : public Base { }; class Different { }; class X { public: template <typename T> static const char *func(T *data) { // Do something generic... return "Generic"; } static const char *func(Base *data) { // Do something specific... return "Specific";...

CMFCPropertyGridProperty numeric input

Hi All, I'm using MFC feature pack and I have a dockable properties window. How do I restrict the user from typing any other characters but numbers alone in the values field? Thanks... ...

native win32 gui programming in c++ or choose wxWidgets ?

Hello all i like to write GUI software ( i have no experience in GUI programming ) i need it to be small as possible and fast GUI and native Look and Feel in one self contained exe . only on windows from windows 2000 to windows 7 ( or what ever it called ) . what will be the best choice ? win32 api or wxWidgets? ...

Running the executable does nothing

Hi all, I was writing a sample example involving multiple files. The detailed code is as follows. main.cpp #include <algorithm> #include <iomanip> #include <ios> #include <iostream> #include <stdexcept> #include <string> #include <vector> #include "grade.h" #include "Student_Info.h" using std::cin; using std::cout; using std::domain...

completely removing a vector c++

Hi , I'm having problems removing a vector from a "multidimensional vector" I would like to achieve this: 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 4 for example vector<vector<int>>vec; for i...//give vec values... vec[3].erase(vec.begin(),vec.end()); It seems like us...

pointer arithmetic on vectors in c++

i have a std::vector, namely vector<vector<vector> > > mdata; i want pass data from my mdata vector to the GSL function gsl_spline_init(gsl_spline * spline, const double xa[], const double ya[], size_t size); as ya. i already figured out that i can do things like gsl_spline_init(spline, &(mgrid.front()), &(mdata[i][j][k].front()),...

Messaging Protocol

How should I design my message protocol so that I distinguish between user data and termination of the message. For example I take input from user to send it to client over TCP/IP, now the client-side needs to know the length of message, what I thought that I use some kind of termination by which the client recognizes that message end h...

C++ and QT4.5 - is passing a const int& overkill? Does pass by reference helps in signals/slots?

Two questions rolled into one here... I have a number of functions which are called multiple times per frame for a real-time video processing application. Taking advice about const and pass by reference, the functions have a signature somewhat like this void processSomething(const int& value); As I keep typing the few extra character...

How virtual is this?

Hi, can you explain me why: int main (int argc, char * const argv[]) { Parent* p = new Child(); p->Method(); return 0; } prints "Child::Method()", and this: int main (int argc, char * const argv[]) { Parent p = *(new Child()); p.Method(); return 0; } prints "Parent::Method()"? Classes: class Parent { publ...

astyle formatting multiple line <<

I'm using astyle which is great for applying standard style to existing code. However I've noticed that when it comes across this: ostringstream myStream; myStream << 1 << 2; it reformats to this: ostringstream myStream; myStream << 1 << 2; Here's my options file: (version 1.23) --indent=spaces --brackets=break --indent...

Newbie: C++ destructor problem

I have to write a stack class template using arrays in C++ for my assignment. Here is my code. #include <iostream> template <typename Type> class Stack { private: int top; Type items[]; public: Stack() { top = -1; }; ~Stack() { delete[] items; }; void push(Type); bool isEmpty() const; Type pop(); Type peek() const; }...

C++ - locale-independent "atof"?

I'm parsing GPS status entries in fixed NMEA sentences, where fraction part of geographical minutes comes always after period. However, on systems where locale defines comma as decimal separator, atof function ignores period and whole fraction part. What is the best method to deal with this issue? Long/latitude string in stored in chara...

Why does the code crash?

Looking on the internet for C++ brainteasers, I found this example: #include <iostream> using namespace std; class A { public: A() { cout << "A::A()" << endl; } ~A() { cout << "A::~A()" << endl; throw "A::exception"; } }; class B { public: B() { cout << "B::B()" << endl; throw...

Developing a facebook app with c++

Hi, I'm a computer science student with experience in C/C++ and I want to have a go at developing a simple facebook app. Can anyone recommend a good website and/or editor? Is it doable with C++ or do I need to learn another language? Thanks ...