c++

C++ restrict implicit construct to specific value

hello Suppose: struct P { P(int v); }; int v; P p = 0; // allow P q = v; // Fail at compile time How can achieve that? any template trick? I am trying to write allocator which has special pointer properties. unfortunately std implementation uses implicit conversion from int to NULL pointer: { return __n != 0 ? _M_impl.allocat...

Project Euler Problem 12 - C++

I'm working on problem 12 regarding the first triangle number with 500 divisors. I tried to brute force the solution. I get 300 divisors in about 35 seconds and can't get 400 within 10 minutes. I'm going to alter my solution to use the prime factor method but I've seen now that people are still getting this solution with brute force i...

Are type fields pure evil?

As discusses in The c++ Programming Language 3rd Edition in section 12.2.5, type fields tend to create code that is less versatile, error-prone, less intuitive, and less maintainable than the equivalent code that uses virtual functions and polymorphism. As a short example, here is how a type field would be used: void print(const Shape ...

Bad C++ programmer behaviors in C#

Possible Duplicate: Most common or vicious mistakes in C# development for experienced C++ programmers I'm a long time C++ programmer about to start working on C# projects. What are some conceptual changes to be aware of, and most importantly, what should I avoid doing in C# that I would normally do in C++? What bad habits do ...

C++ Deallocating objects stored in a vector

I have a class that creates a vector of objects. In the deconstructor for this class I'm trying to deallocate the memory assigned to the objects. I'm trying to do this by just looping through the vector. So, if the vector is called maps I'm doing: Building::~Building() { int i; for (i=0; i<maps.size(); i++) { delete[] &m...

[C++] Need help about monitoring txt file and reading new(last) entry(word) from that txt file

Hi! This is my first contact with C++.I have to make program that will monitor one .txt or .doc file and read every new(last) entry(word) from it.Only thing that I was able to do by now is to completely read txt file, but that is not the point, I can't even get only last word from txt file so I would really appreciate your help with this...

Delete parts of a dynamic array and grow other

I need to have a dynamic array, so I need to allocate the necessary amount of memory through a pointer. What makes me wonder about which is a good solution, is that C++ has the ability to do something like: int * p = new int[6]; which allocates the necessary array. What I need is that, afterwards, I want to grow some parts of this arr...

boost library..........pre-built variants??

Hi, im just installing the boost library using an installer. Its asking me which variants (about 8 options, 6 multithreaded and 2 single threaded) do i want to install. Im only installing this to get to grips and have a practice with boost, so im unsure? Also, how do i use the libraries from VS02010 once ive 'installed' them using the ...

How to handle exceptions from C++ via SWIG to Java

We are implementing a wrapper on C++ code for exposure to Java clients. I have seen the SWIG documents about exception handling but what does this translate to in coding terms in the three layers (C++/SWIG/Java)? If anybody has working example(s) or advice, I would be grateful. ...

C++ equivalent of mbsrtowcs and wcsrtombs using locales and streams

Is there a C++ equivalent of mbsrtowcs and wcsrtombs type functions using std::locale and C++ streams functionality? I'm trying to figure out the best way to convert back and forth between std::string and std::wstring using the standard library. It seems std::locale can almost do this, but I'm a little iffy on some details, or on what l...

Getting eclipse c++ set up on linux?

I downloaded the c++ version of eclipse from the eclipse website. This installed then when i ran the basic hello world code, it wouldn't compile. What else do i need to install to get c++ compiling on eclipse? I thought linux already had what it needed for c++ building/running? Ive googled around but the advice is for older versions of ...

Compiling libpng and using it with netbeans and mingw.

I have only previously used visual studio for developing c++ but I've just moved to netbeans and am having some issues. I got mingw installed so that my projects will compile but I dont know how to add external libraries to that. I want to use a static library, not a dll. The library I specifically am looking at is libpng I hope this ...

Formating columns in C++

I have the following program that generates a multiplication table. A formating problem arises when the outputs reach the double digits. How do I straighten out the columns? #include <iostream> using namespace std ; int main() { while (1 != 2) { int column, row, c, r, co, ro; cout << endl ; cout << "Enter the numb...

I need a container that supports efficient random access and O(k) insertion and removal

I have tried again to ask the same question, but I ended up asking a different question by not providing essential information about my problem. I implement a data structure which is a tree. Each node of this tree has an array/vector/(random access structure) with all its children which can be arbitrary many. The insertion/removal of el...

Crazy C++ iterator error - pointer keeps changing!

I'm writing a binary search tree for school, and part of the assignment is to write a find function. Here's my code: typedef BSTIterator<Data> iterator; iterator find(const Data& item) const { BSTIterator<Data> iter = this->begin(); BSTIterator<Data> end = this->end(); while (iter != end) { if (*iter == item) { return it...

C++ operators question

Given that x = 2, y = 1, and z = 0, what will the following statement display? printf("answer = %d\n", (x || !y && z)); it was on a quiz and i got it wrong, i dont remember my professor covering this, someone enlighten me please... i know the answer i get is 1, but why? thnx ...

Binary * Operator Not Found

I have a vector class with a properly overloaded Vect*float operator and am trying to create the global/non-member float*Vect operator as follows: (Note this is a heavily edited sample) class Vect { public: Vect::Vect(const float p_x, const float p_y, const float p_z, const float p_w); Vect operator*(const float p_sc...

Mock objects in C++

What are Mock objects? Can you please explain the concept? How to make use of Mock objects in C++? Any source examples will be highly helpful. ...

Copy Constructor Being Called on the Wrong Object

I'm currently implementing a copy constructor for a Linked List class. When I create a new instance of the class with another Linked List as a parameter, the constructor is being called for the object I'm passing as the parameter. This is leaving me confused beyond belief. Here is the section necessary to understand what's going on in th...

applying texture another problem directx c++

ok i got everything working. the texture only applys for two sides only of the cube the other sides won't display the correct texture. here is my code // Monopoly.cpp : Defines the entry point for the application. // #include "stdafx.h" #include "Monopoly.h" #define MAX_LOADSTRING 100 // Global Variables: HINSTANCE hInst; ...