c++

Why might using a "long long" in C or C++ be a bad thing?

Why might using a "long long" in C or C++ be a bad thing? I was compiling a runtime library the other day and in the code it checks to see if longs are 64bits and if not it uses a long long. But along with that, it sends out a #warning "using long long". I can't think of any reason for the "long long" being a warning unless it was lefto...

Static data on iphone c++

I have data for countries which include Name, Population, Area etc for countries... What is the best way to store them, I was thinking of static arrays in header files ...? I am using c++ primarily for some game on iPhone Should I consider other options like sqlite, plists, dictionaries ....? ...

Scope of exception object in C++

What is the scope of the exception object in C++? does it go out of scope as soon as catch handler is executed? Also, if I create an unnamed exception object and throw it, then while catching that exception does it matter if I catch it by const reference or a non-const reference? ...

How to prevent compiler doing implicit typecasting in for the class constructor argument?

#include <iostream> using namespace std; struct testarray{ int element; public: testarray(int a):element(a){} }; class myarray { public: testarray i; public: myarray(testarray a) : i(a){ } } ; int main() { myarray objArray[3] = {1,2,3}; return 0; } The above code compiles fine in Visual C++ ...

How can I add a wxIcon to my frame app?

I've looked all over the net and can't seem to find a standard way of including a wxIcon in my wxWidgets app that actually works! I've tried converting the icon to an XPM and including that I've also tried loading the bitmap but whatever I do it seems to compile but the icon never appears! ...

Why is there a class keyword in C++?

This question came to my mind when I learned C++ with a background of C. Even if there was a struct why did Stroustrup felt it was necessary to introduce the class keyword? I tried asking people at that time but couldn't get a satisfactory answer. So can the Stack Overflow community answer it? ...

Is this valid C++?

struct SomeStruct { int a; int b; }; SomeStruct someFn( int init ) { SomeStruct ret = { init, init }; //... return ret; } void someFn2( SomeStruct* pStruct ) { // .. } int main( ) { someFn2( &someFn(32) ); return 0; } ...

CMake RequireAdministrator

Hello :) I'm trying to set the RequireAdministrator manifest flag on an executable I'm building with CMake and Visual Studio. Any ideas on how to direct CMake to set that option? Thanks! Billy3 ...

C++ class, its base class and circular include includes

FILE #1 (foo.h): #ifndef FOO_H_ #define FOO_H_ #include "baseclass.h" #include "bar.h" class Bar; class Foo : public baseclass { public: bar *varBar; }; #endif FILE #2 (bar.h): #ifndef BAR_H_ #define BAR_H_ #include "foo.h" class Foo; class Bar { public: Foo *varFoo; }; #endif FILE #3 (baseclass.h): #ifndef BASECLASS_H_ #define BA...

More Effective C++ advice?

I recently purchased a load of new C++ books to take my skills to the next level. This list includes the three main Scott Meyers texts {Effective C++, More Effective C++, and Effective STL}. I've been reading all three of them but I did notice early on that 'More Effective C++' hasn't been updated since 1996. Can any expert C++ program...

LPD3DXFONT DrawText using DT_CALCRECT?

How do I use DT_CALCRECT to determine my rectangle bottom and right coords? e.g I have this rect: RECT textPos; textPos.left = 100; textPos.right = 100; What do I do next to calculate the rect and draw the text? ...

Which method of incrementing is superior in C++?

I saw someone use this method to increment a variable: r = (r + 1) & 0xf; Is that method better/faster than just using: r++; Why would someone use a bitwise and, with 0xf, if it just duplicates? ...

Can you tell iostreams which characters to treat as whitespace?

So that you could do something like this, for instance: std::string a("01:22:42.18"); std::stringstream ss(a); int h, m, s, f; ss >> h >> m >> s >> f; Which normally requires the string to be formatted "01 22 42 18". Can you modify the current locale directly to do this? ...

Shifting elements in array C++

Hello, Im wondering why my data in 'intFront' does not stay the same. Im shifting the elements in my array left: void stack::rotate(int nRotations) { for (; nRotations > 0 ;) // Number of Rotations to the left { intFront = &items[top+1].n; for ( int shiftL = 0; shiftL < count-1; shiftL++ ) { it...

Linux optimistic malloc: will new always throw when out of memory?

I have been reading about out of memory conditions on Linux, and the following paragraph from the man pages got me thinking: By default, Linux follows an optimistic memory allocation strategy. This means that when malloc() returns non-NULL there is no guarantee that the memory really is available. This is a really bad bug. In case it...

Boost::Archive causing weird linker error.

Does anyone have a clue why those two lines would cause that linker error? std::ifstream ifs("filename.file"); boost::archive::binary_iarchive iarchv( ifs ); Error 8 fatal error LNK1104: cannot open file 'F:\dev\project\build\win32-unit\tests\Debug\framework_core_tests.lib' ramework_core_tests framework_core_tests T...

Transforming multiple iterator elements

My problem is more complex than this, so I've narrowed it down to a very simple example that would show me enough to know how to handle the rest. Say I have an input iterator. I want make a new input iterator derived from it, where each element is the combination of multiple sequential elements of the original input with the following p...

c++ - convert pointer string to integer

I am trying to convert treePtr->item.getInvest() which contains a string to an integer. Is this possible? ...

problem passing in istream argument to a class constructor.

I have the following code in my header file: class Factovisors { public: Factovisors(std::istream& strm):strm_(strm) { } void run() { unsigned int n,m; while (!strm_.eof()) { strm_ >> n >> m; if (isFact(n,m)) std::cout << m << ...

What are the most surprising elements of the C++ standard?

I've decided to get more acquainted with my favorite programming language, but only reading the standard is boring. What are the most surprising, counter-intuitive, or just plain weird elements of C++? What has shocked you enough that you ran to your nearest compiler to check if it's really true? I'll accept the first answer that I won...