c++

C++: Storing childs of a class in variables with it's type

I am currently working on a 2D game project and I want to switch from Delphi to C++. In Delphi, I could declare an array which had the type of a class Entity, and I could put Entitys as well as objects of classes which are derived from Entity into it. This would be very important for me, as it seems logical that all entities should be ...

Moving from C++ to C

After a few years coding in C++, I was recently offered a job coding in C, in the embedded field. Putting aside the question of whether it's right or wrong to dismiss C++ in the embedded field, there are some features/idioms in C++ I would miss a lot. Just to name a few: Generic, type-safe data structures (using templates). RAII. Espe...

Beginner template compile error - Having trouble passing function as arg

Hello everyone, Most of my classes have lists as private data members. As such, most of them also have adder/remover public members. I noticed I was writing basically the same thing for each of the adders, so I thought I'd turn it into a template. Here's what I've got: template <class N, class I> void add(N element, std::list<N> & con...

How can I write a variable of a user-defined type into a stream

I dont mean a variable in a class but a default value for the class as a whole. struct Scalar { unsigned int value; void toThePowerOf(int power); // etc. } I'd like to be able to do something like Scaler foo; foo.value = 2; foo.toThePowerOf(2); std::cout << foo << std::endl; // Outputs 4! Is that possible in C++? ...

C++ backend with C# frontend?

Hi guys, I have a project in which I'll have to process 100s if not 1000s of messages a second and process/plot this data on graphs accordingly (The user will search for a set of data in which the graph will be plotted in real time, not literally having to plot 1000s of values on a graph). I'm having trouble understanding using dlls fo...

Typcasting vector<object> in C++?

I have two classes, obstacle and boid, boid inherits from obstacle. Now I want to write some functions that can work with objects of both classes, so that passing vector<boid> does work as well as vector<obstacle>. When I typecast like this and try to access the size of the vector I get a number of 1840700394 instead of 60: vector<boi...

Any reason why an std::ofstream object won't close properly?

I noticed in my C++ code that anytime I close an std::ofstream object I'm unable to reopen the file I closed with std::ifstream. std::ifstream's open function will always fail. Is there anything 'extra' I can do to ensure that my std::ofstream object closes properly? Someone's probably going to ask to see my specific code so for the sa...

How to release the reference of bind arguments boost::signals2::signal keeps?

I found some objects in my C++ program can't be released due to the Signal2 of boost won't release those arguments in object created by boost::bind. Here is the code to reproduce the problem: #include <iostream> #include <string> #include <boost/bind.hpp> #include <boost/signals2.hpp> #include <boost/shared_ptr.hpp> using namespace s...

overloading operator new without overloading operator delete

HI All I have the simple code below. I defined operator new for my class without operator delete. According to valgrind --leak-check=yes PROGRAM_NAME I have a mismatch i.e. I am allocating using new[] for arrays, but I am deallocating with simple delete for non array. Do you know why? Regards AFG #include<string> #include<new> class...

Proc_open() c++/python problem

Hey, everyone I'm trying to make a call for a c++ / python file with proc_open (bi-directional support needed). After doing some on-line research i found created this code:(I first tried it with c++, after failure i tried pyhton aswell) Php: <?php $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 =...

When encoding actually matters? (e.g., string storing, printing?)

Just curious about the encodings that system is using when handling string storing(if it cares) and printing. Question 1: If I store one-byte string in std::string or two-byte string in std::wstring, will the underlying integer value differ depending on the encoding currently in use? (I remember that Bjarne says that encoding is the map...

Where is my base created?

If I have: struct Base { }; struct Derived : Base { }; And I create Derived in main: Derived* d = new Derived; where (on heap or on stack) is my base created? Am I reasoning correctly that a Base is a part of a Derived so it is created wherever Derived is created? Or does it work in some other way? ...

Is there a better way to initialize an array?

Hello all, Given an array map with size of 256, what is the best way to initialize it so that each element is false? bool map[256]; for (int i=0; i<256; i++) { map[i] = false; } Thank you ...

i want to do project on Pc to mobile calling Suggest me the start up and technologies protocols i need to learn

i want to do project on Pc to mobile calling(like we call from mobile to mobile through internet i wanna connect from pc to mobile ) Suggest me the start up ideas and technologies protocols i need to learn ...etc Suggest me to Kick start my work of first learn it ...

Move ctor is not called

Am I doing something wrong (again)? #include <iostream> using std::cout; struct Map { Map() { cout << "Map()\n"; } Map(const Map& pattern) { cout << "Map(const Map& pattern)\n"; } Map(Map&& tmp) { cout << "Map(Map&& tmp)\n"; } }; Map createMap() { return Map(); } int m...

slow down a process ?

How can i slow down a windows process ? I understand that i need to hook queryperformancecounter but what do i need to do next ? Plase help ...

Alternatives to writing an ODBC driver

We are storing allot of time series data into our own proprietary "database". In the next version of our system we want to give our users a simple query mechanism to extract the raw data from the database (as a complement to the reports our system can create) by using standard tools. I have looked at the possibility to write an ODBC dri...

C++ Program crashes when reading object from random access file

Hi, I have the following User.h that holds several attributes (strings). User.cpp has all the definitions. //User.h #ifndef USER_H #define USER_H #include<iostream> #include <cstring> using namespace std; class User{ string username; public: User(); string getUsername() const; vo...

C++ Gdiplus::Font changing font size and family

Look this code Gdiplus::Graphics g(hDC); Gdiplus::Font *f = new Font(L"Times new roman", 16); Gdiplus::SolidBrush b(Gdiplus::Color(255,0,0,0)); g.DrawString(L"Hello", 5, f, &Gdiplus::StringFormat(), &b); // Now i want to change font styles // using f->setSize() or f->setFontFamily(). g.DrawString(L"Hello", 5, f, &Gdiplus::StringForma...

Line Counter for VS 2010

Hi everybody, I'm looking for a line counting tool like Project Line Counter by Oz Solomon: Project Line Counter. This add-in worked perfectly for me with VS 2005 and 2008. But, unfortunately, Oz has no time to develop it further or to adapt it to VS 2010. Do you know some great line counting tool for C++ code that perferably (but not ...