c++

Seg fault vector<vector<list<Object*> > > push_back

I have a 3D vector defined like this... std::vector<std::vector<std::list<Object*> > > m_objectTiles; I have this code... void ObjectManager::AddObject( Object *object ) { m_objects.push_back( object ); m_objectTypes.insert( std::make_pair( ObjectAttorney::GetType( object ), object )); int x = ObjectAttorney::GetTileX( ob...

C++ boost/asio client doesn't connect to server.

I am learning boost/asio ad wrote 2 programs(client and server) from e-book with minor changes. Basically it should connect to my server. When i try to connect to outside world(some random http server ) all is good and it works but when i change destination to "localhost:40002" it says invalid argument. client code: #include <boost/asi...

state-of-the-art C++ projects

Hello I like to go through existing software projects as a source of learning and new ideas. doing so I discover things that I did not think were possible in your opinion, what is the top state of the art C++ project that you have used/develop/extended? can you state reasons why you consider it state of the art and what you can learn ...

C++ Problem with destructor called when removing element from STL container

Say I have 2 containers storing pointers to the same objects... std::list<Foo*> fooList; std::vector<Foo*> fooVec; Lets say I remove an object from one of these containers via one if its methods, for example... std::vector<Foo*>::iterator itr = std::find( fooVec.begin(), fooVec.end(), pToObj ); fooVec.erase( itr ); CppReference ...

Dynamic Programming Problem

I am just unable to get the hang of dp. I know what I've to do but am just unable to implement it.E.g this practice problem from 'Codechef' http://www.codechef.com/problems/MIXTURES/ If i consider the min smoke for mixtures i to j as m[i,j] then for k<- i to j m[i,j]=min(m[i,k]+m[k+1,j]+cost of mixing the resulting mixtures) Is ...

Can this be done?

I was wondering if the following was possible: class foo { virtual void bar(); } class izy : public foo { int a; virtual void bar() { a = 2; } } foo *anyfoo = new izy; anyfoo.bar(); essentially what I want to know is, can I add the variable a or will a be nonexistant since its not part of the base class foo? ...

Is this a "recognised" OO pattern? Need sanity check!

Say if I want to extend the functionality of a range of objects that I cannot change - for instance for adding formatting, and don't want to derive a huge amount of classes to extend the functionality - would the following considered bad? (I'm using int and float as an example, but in my program I have about 20 or 30 classes that will e...

what is meaning of c++?

what is meaning of c++? ...

Implementing something like std::vector.back()

I would like to implement something like this because my application is divided into scenes and this gets sort of messy: glEngine.scene[glEngine.current.currentScene].layer[glEngine.scene[glEngine.current.currentScene].currentLayer].Shapes.push_back(CGlShape()); instead I'd want to be able to do something like this: glEngine.Scene()....

Qt - There is a bug?

I face a very serious situation. By writing this question I hope that really professionals will express their opinion regarding to the problem I am going to describe. I have reported a bug in http://bugreports.qt.nokia.com/ : I have created QPropertyAnimation for maximumWidth property of QTextEdit and it does not work (it immediately...

Another 'x was not declared in this scope'

Hi to all, this is my first question here. Writing some code, i receive this error from g++: "Entity was not declared in this scope", in this context: #ifndef Psyco2D_GameManager_ #define Psyco2D_GameManager_ #include <vector> #include "Entity.h" namespace Psyco2D{ class GameManager{J private: std::vector<Entity> enti...

How to avoid the "swapping of death" during development?

Probably everyone ran into this problem at least once during development: while(/*some condition here that somehow never will be false*/) { ... yourvector.push_back(new SomeType()); ... } As you see the program starts to drain all system memory, your program hangs and your system starts to swap like crazy. If you don't rec...

IntSetArray implementation in c++

i have trying to imlement IntSetArray in c++ it compiles fine but result is wrong first 300 is ok and other numbers are below zero something very strange numbers .e.g -8231313 something like this) what is wrong? it is code #include <iostream> using namespace std; int quantity=10; class Set { private : int n,*x; public: S...

Using Unicode in a C++ source file

I'm working with a C++ sourcefile in which I would like to have a quoted string that contains Asian Unicode characters. I'm working with QT on Windows, and the QT Creator development environment has no problem displaying the Unicode. The QStrings also have no problem storing Unicode. When I paste in my Unicode, it displays fine, somethi...

Get the defaults programs

Hello, i use c++ and qt for a project. I would to know how i can get the default program : default navigator, default mail client, default editor ... I found for Linux - Gnome: gconftool! What is for Windows, Mac Os or Linux (KDE) ? Thanks you. ...

How to turn .h file +dll into some kind of .Net wrapper?

How toturn .h file +dll into some kind of .Net wrapper? or something like that? (no C\C++ sources just h files) ...

How do detect if an address will cause an access violation?

I'm creating a class for a Lua binding which holds a pointer and can be changed by the scripter. It will include a few functions such as :ReadString and :ReadBool, but I don't want the application to crash if I can tell that the address they supplied will cause an access violation. Is the a good way to detect if an address is outside of...

How to get rid of "unsafe" warnings (strcpy, sprintf, strdup)

I'm trying to get rid of some compiler warnings that say strcpy, sprintf, etc are unsafe. I get why they're unsafe, but I can't think of a good way to fix the code, in a C++ style. Here's a excerpt of the code: extList->names[i]=(char *)malloc(length*sizeof(char)); strcpy(extList->names[i],extName); // unsafe // str...

C++ equivalent of fscanf() ?

And please don't say it's fscanf() ;P I'm trying to replace this line: if ( fscanf(fp, "P%c\n", &ch) != 1 ) If I understand correctly, it tries to read in a char and store it to &ch, only if it's between a 'P' and a '\n'. Is that right? And if it succeeds, it returns 1 (the number of characters it read)? I'm trying to come up with ...

How can I use GNU Flex in Visual C++?

Hello :) I'm trying to use Flex with Visual C++. However, the generated lexer (which is empty and has no rules) throws these errors while building: configurationlexer.cpp(967): error C3861: 'read' identifier not found configurationlexer.cpp(967): fatal error C1903: unable to recover from previous error(s); stopping compilation The so...