c++

Workarounds for the forward-declared class enumeration problem?

I am maintaining a large code base and am using a combination of forward declarations and the pImpl idiom to keep compile times down and reduce dependencies (and it works really well,) The problem I have is with classes that contain public enumerations. These enumerations cannot be forward declared so I am left with no option but to in...

Should "delete this" be called from within a member method?

I was just reading this article and wanted SO folks advice: Q: Should delete this; be called from within a member method? ...

Qt QString cloning Segmentation Fault

Hi, I'm building my first Qt app using Qt Creator, and everything was going fine until I started getting a strange SIGSEGV from a line apparently harmless. This is the error: Program received signal SIGSEGV, Segmentation fault. 0x0804e2fe in QBasicAtomicInt::ref (this=0x0) at /usr/lib/qt/include/QtCore/qatomic_i386.h:120 By back...

Why are operators sometimes stand-alone and sometimes class methods?

Why is that sometimes an operator override is defined as a method in the class, like MyClass& MyClass::operatorFoo(MyClass& other) { .... return this; }; and sometimes it's a separate function, like MyClass& operatorFoo(MyClass& first, MyClass& bar) Are they equivalent? What rules govern when you do it one way and when you do it t...

Optimizing a pinhole camera rendering system

Hello, I'm making a software rasterizer for school, and I'm using an unusual rendering method instead of traditional matrix calculations. It's based on a pinhole camera. I have a few points in 3D space, and I convert them to 2D screen coordinates by taking the distance between it and the camera and normalizing it Vec3 ray_to_camera = (...

gcc debug log files on Windows?

I am starting to ship Qt applications built using MinGW and have a question about debug logs. When using code compiled with MSVC, if my app were to crash a log file or mini-dump could be created that was invaluable when diagnosing the problem. There is even a very cool library called crashrpt that can generate and then email this log f...

Error making C++ functions virtual

The error states: "error: virtual outside class definition" Cpp members in question: virtual void Account::creditBalance(double plus) { if(plus > 0) balance += plus; else cout << "Cannot credit negative."; } virtual void Account::debitBalance(double minus) { if(minus <= balance) balance -= minus; else ...

portable signed/unsigned byte cast,C++

I am using signed to unsigned byte(int8_t) cast to pack byts. uint32_t(uint8_t(byte)) << n This works using GCC on Intel Linux. Is that portable for other platforms/compilers, for example PowerPC? is there a better way to do it? using bitset is not possible in my case. I am using stdint via boost ...

should i put .hpp and .cpp in the same fold or in ./src and ./hdr respectively?

Hi, it seems that separate them into src and hdr is a popular solution. however, this is not the case in Netbeans: by default, netbeans will put both hpp and cpp files in the same directory. questions: should I separate them or not? why? if 1 is yes, is there any way to automatically set this in Netbeans? ...

what's the difference between hpp and hxx ?

hi, for gcc they should be the same, right? which one of them is more popular , i am now preparing a project from scratch and i would like to pick one among these 2. thanks ...

Who can tell me what this bit of C++ does?

CUSTOMVERTEX* pVertexArray; if( FAILED( m_pVB->Lock( 0, 0, (void**)&pVertexArray, 0 ) ) ) { return E_FAIL; } pVertexArray[0].position = D3DXVECTOR3(-1.0, -1.0, 1.0); pVertexArray[1].position = D3DXVECTOR3(-1.0, 1.0, 1.0); pVertexArray[2].position = D3DXVECTOR3( 1.0, -1.0, 1.0); ... I've not touched C++ for a while - hence th...

What is the best single-source shortest path algorithm for programming contests?

I was working on this graph problem from the UVa problem set. It's a single-source-shortest-paths problem with no negative edge weights. From what I've gathered, the algorithm with the best big-O running time for such problems is Dijkstra with a Fibonacci heap as the priority queue, although practically speaking a binary heap is easier t...

Why do C++ class definitions on Windows often have a macro token after 'class'?

I am trying to understand an open source project, where I came across the following class declaration: class STATE_API AttributeSubject : public AttributeGroup, public Subject { public: AttributeSubject(const char *); virtual ~AttributeSubject(); virtual void SelectAll() = 0; virtual const std::string TypeName() const; ...

casting via void* instead of using reinterpret_cast

Hi, I'm reading a book and I found that reinterpret_cast should not be used directly, but rather casting to void* in combination with static_cast: T1 * p1=... void *pv=p1; T2 * p2= static_cast<T2*>(pv); instead of: T1 * p1=... T2 * p2= reinterpret_cast<T2*>(p1); However, I can't find an explanation why is this better than the dire...

why unsigned int 0xFFFFFFFF is equal to int -1?

perhaps it's a very stupid question but I'm having a hard time figuring this out =) in C or C++ it is said that the maximum number a size_t (an unsigned int data type) can hold is the same as casting -1 to that data type. for example see http://stackoverflow.com/questions/1420982/invalid-value-for-sizet Why?? I'm confused.. I mean, (t...

Open Watcom C++ Compiler Compilation Problem

I'm trying to compile a basic "hello world" file with the Open Watcom C++ compiler for Windows. Here's the error I get: wpp386 hello.cpp Open Watcom C++32 Optimizing Compiler Version 1.8 Portions Copyright (c) 1989-2002 Sybase, Inc. All Rights Reserved. Source code is available under the Sybase Open Watcom Public License. See http://w...

C++ creating image

Hi, I haven't been programming in C++ for a while, and now I have to write a simple thing, but it's driving me nuts. I need to create a bitmap from a table of colors: char image[200][200][3]; First coordinate is width, second height, third colors: RGB. How to do it? Thanks for any help. Adam ...

Cross platform c++ with libcurl

Hi, I am a perl developer that has never went into the client side programming of things. I'd like to think that I'm a pretty good developer, except I know that my severe lack of knowledge of the way desktop programming really takes away from my credibility. That said, I really want to get into doing some desktop applications. I want...

C++ "Scrolling" through items in an stl::map

I've made a method to scroll/wrap around a map of items, so that if the end is reached, the method returns the first item and vice-versa. Is there more succinct way of doing this? MyMap::const_iterator it = myMap.find(myKey); if (it == myMap.end()) return 0; if (forward) { it++; if (it == myMap.end()) { it = myM...

What does "symbol value" from nm command mean?

When you list the symbol table of a static library, like nm mylib.a, what does the 8 digit hex that show up next to each symbol mean? Is that the relative location of each symbol in the code? Also, can multiple symbols have the same symbol value? Is there something wrong with a bunchof different symbols all having the symbol value of 00...