c++

Boundary fill problem

hi...Im stuck in this bunch of codes...i cant get the pixel to fill up the circle??...any help #include<iostream> #include<glut.h> struct Color{ float red, green, blue; }; Color getPixel(int x, int y){ // gets the color of the pixel at (x,y) Color c; float color[4]; glReadPixels(x,y,1,1,GL_RGBA, GL_FLOAT, color); ...

String initialization with pair of iterators.

Hi, I'm trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, eos); but this doesn't: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos(fin); /* here eos is at this same position as in_i*/ ...

3d Alternative for D3DXSPRITE for billboarding

I am looking to billboard a sun image in my 3d world (directx 9). Creating a D3DXSPRITE is great in some cases, but it is only a 2d object and can not exist in my "world" as a 3d object. What is an alternative method for billboarding, similar to d3dxsprite? How can I implement it? The only alternative I have currently found is this...

Data Destruction In C++

So, for class I'm (constantly re-inventing the wheel) writing a bunch of standard data structures, like Linked Lists and Maps. I've got everything working fine, sort of. Insertion and removal of data works like a charm. But then main ends, my list is deleted, it calls it's dtor and attempts to delete all data inside of it. For some r...

Passing another class amongst instances

Hi! I was wondering what is the best practice re. passing (another class) amongst two instances of the same class (lets call this 'Primary'). So, essentially in the constructor for the first, i can initialize the outside instance (lets call this 'Shared') - and then set it to a particular value whilst im processing this class in main()...

Serialize Strings, ints and floats to character arrays for networking WITHOUT LIBRARIES

Hello StackOverflow, I want to transmit data over the network, but I don't want to use any foreign libraries (Standard C/C++ is ok). for example: unsigned int x = 123; char y[3] = {'h', 'i', '\0'}; float z = 1.23f; I want this in an char xyz[11]; array. Note: To transmit it over network, I need Network Byte order for the unsigne...

C++, Boost regex, replace value function of matched value?

Specifically, I have an array of strings called val, and want to replace all instances of "%{n}%" in the input with val[n]. More generally, I want the replace value to be a function of the match value. This is in C++, so I went with Boost, but if another common regex library matches my needs better let me know. I found some .NET (C#...

Adding functionality to a handle wrapper.

I have a C++ RAII class for managing Win32 HANDLEs using boost::shared_ptr<> that looks a bit like this: namespace detail { struct NoDelete { void operator()( void* ) {}; }; }; // namespace detail template< typename HANDLE_TYPE, typename HANDLE_DELETER > class CHandleT { public : explicit CHandleT( HANDLE_TYPE handle, bool delete_o...

Making an object orbit a fixed point in directx?

I am trying to make a very simple object rotate around a fixed point in 3dspace. Basically my object is created from a single D3DXVECTOR3, which indicates the current position of the object, relative to a single constant point. Lets just say 0,0,0. I already calculate my angle based on the current in game time of the day. But how ca...

Initializing array of objects with data from text file

I’m getting system error when I try to compile the code below on Visual C++ 2008 Express. What I’m trying to do is to initialize array of objects with data read from file. I think there is something wrong inside the while loop, because when I initialize these objects manually without the while loop it seems to work. Here is the code an...

Which C++ logical operators do you use: and, or, not and the ilk or C style operators? why?

leisure/curiosity question as implied in the title. I personally prefer the new operators as to make code more readable in my opinion. Which ones do use yourself? What is your reason for choosing one over the other one? also Emacs highlights those operators differently so I get more visual feedback when looking at the screen. I know...

OpenGL / C++ / Qt - Advice needed

I am writing a program in OpenGL and I need some sort of interfacing toolbar. My initial reactions were to use a GUI, then further investigation into C++ I realized that GUI's are dependent on the OS you are using (I am on Windows). Therefore, I decided to use QT to help me. My Question is if I am taking the best/appropriate approach to...

Is there a way to improve the speed or efficiency of this lookup? (C/C++)

I have a function I've written to convert from a 64-bit integer to a base 62 string. Originally, I achieved this like so: char* charset = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int charsetLength = strlen(charset); std::string integerToKey(unsigned long long input) { unsigned long long num = input; st...

Template lookup in class?

It's hard to get a word for this. Sometimes I see a class like this: template <typename T> class Wrapper { public: Wrapper(const T& t) : t_(t) {} Wrapper(const Wrapper& w) : t_(w.t_) {} private: T t_; } As far as I can tell this is legitimate code. However, why is the copy constructor allowed to accept a const Wrapper& wit...

Custom system tray icon "balloon tooltips" for Qt?

I know that in the .NET framework there are a handful of alternative third-party controls for normal system tray icon "balloon tips", that allow you to change the colors and add some styling to the balloon. I was wondering if there is something similar for Qt, which allows for better customization of the look, style, and feel of the bal...

Are class variables included in the 7 +- 2 guideline?

I'm wondering in regards to the guideline stating that classes should have around 7 variables +-2, are class variables (class constants) included in this? Ex: class Foo { static const int SOME_THING; static const double SOME_OTHER; static const int BLAH; int m_ThisVariable; double m_ThatVariable; string m_SomeS...

Access violation when calling external function (C++) from Delphi application

I've an external DLL written in C++. The piece below declares a struct type and a function, which, being given a pointer, fills a variable of this type: enum LimitType { NoLimit, PotLimit, FixedLimit }; struct SScraperState { char title[512]; unsigned int card_common[5]; unsigned int card_player[10][2]; unsigned int ca...

Struct initialization of the C/C++ programming language?

I could do struct initialization with code: struct struct_type_id struct_name_id = { value1, value2, value3 }; but could not with: struct struct_type_id struct_name_id; struct_name_id = { value1, value2, value3 }; why I could do it with the former,but could not with the latter with gcc,g++,vc2008,vc6?In other words,why the c/c++ pr...

Given a vector of Lat/Lon pairs, how can I create a vector so that the distance between points is less than or equal to some constant?

Suppose I have an array of coordinates, representing a route. I want to decompose this route so that it contains a point, say every 5 miles. How can I do that? struct Location { double latitude; double longitude; }; vector<Location> route; vector<Location> computeHigherGranularityRoute(const vector<Location>& oldRoute, double ...

A case where named constants are not needed over magic numbers

Obviously the point of using named constants over magic numbers is for code clarity and for not having to go through code changing numbers throughout. However, what do you do if you just have a number used just once in a function? Say you have a short member function that uses an object's velocity (which we'll say won't change) to calcu...