c++

STL erase-remove idiom vs custom delete operation and valgrind

This is an attempt to rewrite some old homework using STL algorithms instead of hand-written loops and whatnot. I have a class called Database which holds a Vector<Media *>, where Media * can be (among other things) a CD, or a Book. Database is the only class that handles dynamic memory, and when the program starts it reads a file form...

relation between access specifiers and using initializer lists for POD types in c++0x.

take two following classes: class Test1{ public: Test1()=default; Test1(char in1,char in2):char1(in1),char2(in2){} char char1; char char2; }; class Test2{ public: Test2()=default; Test2(char in1,char in2):char1(in1),char2(in2){} private: char char1; char char2; }; I know in c++0x both of these classes are considered...

I'm doing funky things with placement new, and things are failing. Workarounds?

I have a very large, spread out class that is essentially a very contrived two dimensional linked list. I want to be able to "compile" it, by which I mean I want to finalize the list, so that only read accesses may be made, and then move all the elements into contiguous memory spaces. My rough solution is this: #include <new> ... MyLis...

operator<<() for template class

I want to overload operator <<() for my own class that is also a template. My classes are as follows: template< typename RefCountType, typename TraitsType = std::char_traits<char>, typename Allocator = std::allocator<typename TraitsType::char_type> > class rep { // ... }; template<typename RepType> class t_zstring { ...

Solving a system of equations programmably?

Possible Duplicate: System of linear equations in C++? I have the following 2 systems of equations: For a,b,c,d: 0 = a * r1_x + b * r1_x * r1_y + c * r1_y + d 1 = a * r2_x + b * r2_x * r2_y + c * r2_y + d 0 = a * r3_x + b * r3_x * r3_y + c * r3_y + d 1 = a * r4_x + b * r4_x * r4_y + c * r4_y + d For e,f,g,h: 0 = e * r1_x ...

Freeing dynamically allocated memory

In C++, when you make a new variable on the heap like this: int* a = new int; you can tell C++ to reclaim the memory by using delete like this: delete a; However, when your program closes, does it automatically free the memory that was allocated with new? ...

OpenGL Hemisphere Texture Mapping

I need to have a hemisphere in opengl. I found a drawSphere function which I modified to draw half the lats (which ends up drawing half of the sphere) which is what I wanted. It does this correctly. However, I don't know what i should do with glTexCoordf to get the textures to map properly onto this half sphere. I'm really not great w...

Using member of template class to instantiate template default parameter in MSVC++

The following piece of code is a reduced sample from the large project I'm trying to port from GCC/G++ to Microsoft Visual C++ 2010. It compiles fine with G++, but with MSVC++, it throws errors, and I'm having trouble understanding why. template <typename A, typename B = typename A::C::D> // line 1 struct foo { typedef int type; }...

question about templates

i have following code #include <iostream> #include <utility> using namespace std; namespace rel_ops{ template<class t>bool operator!=(const t& x, const t& y){ return !(x==y);} template <class t>bool operator>(const t& x,const t& y){ return y<x;} template <class t>bool operator <=(const t& x,const t& y){ return !(y<x);} ...

Progamming / memory / logical issue in code

Can you tell me is there any thing wrong in the code, my application is crashing randomly I cannot find any possible logical or memory error, please help as this is going out of my scope. #define __FN__ "CGD9_gd_ParseAddFieldsProC" int CGD9_gd_ParseAddFieldsProC (CGD_gd_ParseAddFields_Iparam_t *i_param_st_p) { t_gd9adfld_t *p_ext_fi...

C++/STL: XOR of two set

Given two STL sets, I want to find out the XOR of them. Is there an easy, pre-existing way to do that? ...

question about class

Possible Duplicates: Why should I prefer to use member initialization list? C++ - what does the colon after a constructor mean? here is following code class vector2d { public: double x,y; vector2d (double px,double py): x(px), y(py) {} i dont understand this line vector2d (double px,double py): x(px), y(py) {} is...

Dependent Non-Type Template Parameters

Consider the following class: class Foo { enum Flags {Bar, Baz, Bax}; template<Flags, class = void> struct Internal; template<class unused> struct Internal<Bar, unused> {/* ... */}; template<class unused> struct Internal<Baz, unused> {/* ... */}; template<class unused> struct Internal<Bax, unused> {/* ... */}; }; The class...

Mapping class to instance

I'm trying to build a simple entity/component system in c++ base on the second answer to this question : Best way to organize entities in a game? Now, I would like to have a static std::map that returns (and even automatically create, if possible). What I am thinking is something along the lines of: PositionComponent *pos = systems[P...

Declaring two variable in a conditional?

Can I declare two variables in a conditional in C++. The compiler gave an error but still I think I should get an opinion: int main() { double d1 = 0; if((double d2 = d1) || (double d3 = 10)) cout << "wow" << endl; return 0; } ...

istream_iterator leaking memory

All right, you guys were very helpful with my last question, so I'll try another one. This is also homework and while the last one was quite old, this has been submitted and is waiting to be marked. So if there's anything that will bite me it'll probably be this problem. I've obfuscated the class names and such since it's still possible ...

[C++] Diamond sub-problem: non-multiple inheritance in side branch still require class constructor

Strange problem occurred when I tried to "solve" usual diamond problem in a usual way - using virtual inheritance: A / \* both virtual B C \ / D However my base class A doesn't have default constructor, so I was to call it manually from D. However when I try to add a class E into this diamond as C-inherited A / \* both vir...

Xerces-C++ DOM node line/column number location

Hi, I'm writing a custom XML validator using Xerces-C++. My current approach loads the document into a DOM, and then checks are performed on it. What I need is a way to access the line/column number of a node in the DOM. I've been reading the API docs and googling, but I'm coming up short. Is it possible to somehow retrieve this kind of...

Printing in Full-screen Windows CE app

How do you do it? This page says you need to call PrintSetupDlg, but this code PAGESETUPDLG printDialog; ZeroMemory(&printDialog, sizeof(printDialog)); printDialog.lStructSize = sizeof(printDialog); printDialog.hwndOwner = hwnd; //or = NULL PageSetupDlg(&printDialog); freezes the program on the call to PageSetupDlg - it becomes unre...

What is the Linux equivalent of: MultiByteToWideChar & WideCharToMultiByte?

I am working with a class that wraps the std::wstring, this code needs to be cross platform, are there equivalents to the windows functions: MultiByteToWideChar & WideCharToMultiByte on linux? Thank you. ...