c++

How to use hash_map with char* and do string compare?

I was using std::hash_map<char*,T> and somehow managed to make it work but have now discovered that the default compare function, euqal_to<char*> does a pointer compare rather than a string compare. I've fixed this by making my own compare type (using C's strcmp and it's about 5 LOC) but I'd be slightly shocked if there wasn't one alread...

Transparent sprites in c++ with Allegro

I'm learning to use Allegro. I'm trying to make my character cut out. How do I key out a certain color from my bitmap? which way is used for allegro? Thanks ...

How to draw a (bezier) path with a fill color using GDI+?

I am making a SVG renderer for Windows using the Windows API and GDI+. SVG allows setting the 'fill' and 'stroke' style attributes on a Path. I am having some difficulty with the implementation of the 'fill' attribute. The following path represents a spiral: <svg:path style="fill:yellow;stroke:blue;stroke-width:2" d="...

Is this C++ reassignment valid?

Sorry for the basic question, but I'm having trouble finding the right thing to google. #include <iostream> #include <string> using namespace std; class C { public: C(int n) { x = new int(n); } ~C( ) { delete x; } int getX() {return *x;} private: int* x; }; void main( ) { C obj1 = C(3); obj1 = C(4); cou...

C++ copy constructor causing code not to compile ( gcc )

I have the following code which doesn't compile. The compiler error is: "error: no matching function to call B::B(B)", candidates are B::B(B&) B::B(int)" The code compiles under either of the following two conditions: Uncommenting the function B(const B&) change 'main' to the following int main() { A a; B b0; ...

Sockets in MinGW

I was just trying to build netcat in MSYS using MinGW and realized that MinGW never really ported all of the BSD socket stuff to Windows (eg sys/socket.h). I know you can use Windows Sockets in MinGW, but why did they never make a Windows port of the BSD sockets? I noticed quite a few programs using #ifdef's to workaround the issue. I...

priority_queue<> comparison for pointers?

Hello, So I'm using the STL priority_queue<> with pointers... I don't want to use value types because it will be incredibly wasteful to create a bunch of new objects just for use in the priority queue. So... I'm trying to do this: class Int { public: Int(int val) : m_val(val) {} int getVal() { return m_val; } private: int ...

Performance of Java 1.6 vs C++ ?

Hi, With Java 1.6 out can we say that performance of Java 1.6 is almost equivalent to C++ code or still there is lot to improve on performance front in Java compared to C++ ? Thanks. ...

c++ global constants issue

We have these set of "utility" constants defined in a series of file. The problem arises from the fact that TOO MANY files include these global constant files, that, if we add a constant to one of those files and try to build, it builds the whole entire library, which takes up more than an hour. Could anyone suggest a better way for thi...

Error while calling member function

Hi I have just started using C++ today, and I am working on checkboxes. I have tried using CheckBox1->Checked in an if statement or whatever, but it isn't working. The error is: Error 2 error C2227: left of '->Checked' must point to class/struct/union/generic type EDIT: The Code is: void function () { if (1001->Checked) { ...

How do I input data using the eclipse console? (c++)

I'm trying my hand at c++ and am using fedora eclipse (3.4.2) as my IDE. At the moment I'm trying to enter a string of numbers into the console, get the program to sort them and spit them back out. The program is straight out of a book and works with xcode and through a normal terminal - so I know it's correct. Basically I run the prog...

How to launch an external application on BN_CLICKED?

I'm fairly new to Windows programming. I'm doing a simple launcher app for WinCE using VC++ (not MFC). So far I've created the basic interface and buttons and stuff. I just wanted to know the best way to launch an external application when the user clicks the button (on BN_CLICKED). I found some methods such as ShellExecute, CreateProce...

What happens inside the code of Constructor that compiler executes and supplies Default Constructor ?

Hi, I wanted to What is the Job of Compiler Supplied Constructor ?. Is that constructor does memory allocation and all the stuffs required to create an object. I am not asking this question from member variable initialization point of view. I want to know what happens inside the code of default constructor that compiler executes and su...

Strange compile (?) probem. Visual studio c++ 2008

I don't know much about this stuff. There's an app that I use on an XP netbook for tuning a car. It was working just fine. Then I needed to make a simple modification (output to STDOUT instead of to file) so I got the source from the author. My netbook doesn't have the space for a compiler. I have Visual Studio C++ 2008 on a Windows 7...

Multiple output operators?

Hi, is it possible to define multiple output operators for an enum? I want to use this std::ostream& operator<< (std::ostream& os, my_enum e); operator to (1) print a human readable text and to (2) convert it to some code for storing in a database. Thanks ...

Casting to one class and calling function from sibling class?

I'm getting a pointer to a base class (which is actually a pointer to some derived class). Then I want to call a function on that derived class, but I don't know which one it is. class Base { }; class DerivedOne : public Base { public: void functionA() { int x = 0; } }; class DerivedTwo : public Base { public: ...

in-class initialization of non-integral static data

So I just learned via a compiler error that in-class initialization of arrays is invalid (why?). Now I would like to have some arrays initialized in a template class, and unfortunatly the contents depend on the template parameter. A condensed testcase looks like this: template<typename T> struct A { T x; static const int len = s...

Recursive Fibonacci

I'm having a hard time understanding why #include <iostream> using namespace std; int fib(int x) { if (x == 1) { return 1; } else { return fib(x-1)+fib(x-2); } } int main() { cout << fib(5) << endl; } results in a segmentation fault. Once x gets down to 1 shouldn't it eventually return? ...

Declaring a non static const array as class member

How can we declare a non static const array as an attribute to class. Following code produces compilation error (“'Test::x' : member could not be initialized”)? class Test { public: const int x[10]; public: Test() { } }; ...

Using default printer source tray

In one of my apps I offer the user the ability to change the source tray used when printing. This is straight-forward enough - you modify the dmDefaultSource member of the DEVMODE structure, call ResetDC and all is well. However, I now want to use the default source tray as set on the printer's control panel (ignoring whatever the defa...