c++

C++0x "move from" container

In C++0x, we get an efficiency boost concerning containers with std::move: SomeExpensiveType x = /* ... */; vec.push_back(std::move(x)); But I can't find anything going the other way. What I mean is something like this: SomeExpensiveType x = vec.back(); // copy! vec.pop_back(); // argh This is more frequent (the copy-pop) on adapte...

Why can't I inherit from int in C++ ?

I'd love to be able to do this: class myInt : public int { }; Why can't I ? Why would I want to? Stronger typing. For example, I could define two classes intA and intB, which let me do intA+intA or intB+intB, but not intA+intB. "Ints aren't classes" so? "Ints don't have any member data" Yes they do, they have 32 bits, or whatever....

How to correctly initialize variable of template type?

Hi, suggest i have a template function like following: template<class T> void doSomething() { T a; // a is correctly initialized if T is a class with a default constructor ... }; But variable a leaves uninitialized, if T is a primitive type. I can write T a(0), but this doesn't work if T is a class. Is there a way to initializ...

opengl: glFlush() vs. glFinish()

I'm having trouble distinguishing the practical difference between calling glFlush() and glFinish(). The docs say that glFlush() and glFinish() will push all buffered operations to opengl so that one can be assured they will all be executed, the difference being that glFlush() returns immediately where as glFinish() blocks until all the...

C++: Template Parameter Cyclic Dependency

Hello, This is more a best practice question than a language question in itself, since I already have a working solution to what seems to be a common stumbling block in C++. I'm dealing with a typical cyclic dependency issue in template parameter substitutions. I have the following pair of classes: template<class X> class A { /* ... *...

Add my own compiler warning

When using sprintf, the compiler warns me that the function is deprecated. How can I show my own compiler warning? ...

Operator== in derived class never gets called.

Can someone please put me out of my misery with this? I'm trying to figure out why a derived operator== never gets called in a loop. To simplify the example, here's my Base and Derived class: class Base { // ... snipped bool operator==( const Base& other ) const { return name_ == other.name_; } }; class Derived : public Base { // ......

Network connection setup in constructor: good or bad?

I'm working on a class that handles interaction with a remote process that may or may not be available; indeed in most cases it won't be. If it's not, an object of that class has no purpose in life and needs to go away. Is it less ugly to: Handle connection setup in the constructor, throwing an exception if the process isn't there. H...

button keyboard focus issues

How would one prevent the little dotted square that appears on a button when it has the keyboard focus in a dialog. (w/ apologies for the technical jargon). At one point I hacked together a solution by subclassing a button WindowProc and subverting some windows messages, but wanted to know the correct way. There's actually a problem ...

Visual Studio 2010 C++ compiler - Get current line number when compiling

Hello, i have a question about how to get the current line number while compiling of the VS C++ compiler, IF its possible of course. I know its possible to use the LINE Macro from the preprocessor, but the results i get are not correct (well, at least not what i want). Please tell me its possible :) Thanks in advance edit: I think i...

What is the best way to deal with co-dependent classes in C++?

Say I have a class foo with an object of class bar as a member class foo { bar m_bar; }; Now suppose bar needs to keep track of the foo that owns it class bar { foo * m_pfoo; } The two classes reference each other and without a forward declaration, will not compile. So adding this line before foo's declaration solves that p...

What is copy elision and how it optimizes copy-and-swap idiom

I was reading this Copy and Swap link. i tried reading some links on Copy Elision but could not figure out properly what it meant. Can somebody please explain what this optimization is, and especially what is mean by the following text This is not just a matter of convenience but in fact an optimization. If the parameter (s) binds t...

wxWidgets program I developed has two entries in the process manager. Is this normal or a bug?

I'm developing a program in wxwidgets that has one worker thread that does COM stuff. I just noticed that it has two entries in the task manager. Looks like myapp.exe*32 myapp.exe*32 Is this duplicate entry normal? I noticed most other processes don't. Hmm. What could cause this? I'm using Windows 7 Ultimate 64 bit. ...

c/c++: Curious question about calling function with no arguments with function which returns nothing

Hello, this wierd question just came to my mind. Why isnt it possible to call a function which takes no arguments with a function call as argument which does not return any value (which imho is equivalent to calling a function which takes no arguments with no arguments). f.e. void foo(void) {...} void bar(void) {...} foo(bar()) Don...

How to prevent derived class from making a private/protected virtual function public?

There are good reasons for constructing the base class interface with all virtual functions as private or protected (see this). But then how does one prevent the derived classes (which may be in the hands of external clients) from making the private virtual function as public? In Virtually Yours, the authors talk about this problem, but ...

Explicit Type Conversion and Multiple Simple Type Specifiers

To value initialize an object of type T, one would do something along the lines of one of the following: T x = T(); T x((T())); My question concerns types specified by a combination of simple type specifiers, e.g., unsigned int: unsigned int x = unsigned int(); unsigned int x((unsigned int())); Visual C++ 2008 and Intel C++ Compile...

Problem with re-using a stringstream object

Hi all, I'm trying to use safe practices in handling input with numbers only in C++, so I use a stringstream object as so: #include <iostream> #include <string> #include <sstream> using namespace std; int main() { int first, second; string input; stringstream sstream; cout << "First integer: "; getline(cin, input)...

How can I determine why a call to IXMLDOMDocument::load() fails?

I am trying to debug what appears to be an XML parsing issue in my code. I have isolated it down to the following code snippet: HRESULT CXmlDocument::Load(IStream* Stream) { CComVariant xmlSource(static_cast<IUnknown*>(Stream)); VARIANT_BOOL isSuccessful; * HRESULT hr = m_pXmlDoc->load(xmlSource, &isSuccessful); return (h...

Redirect std*** from C++ to Java for Logging

I have a C++ application and a Java application that need to log messages in the same way. My Java application uses Apache Commons Logging, backed by a Log4j configuration. I need a single log4j configuration so I can change my logging preferences in one location. In my C++ application, I have captured all calls to printf() and fprintf(s...

how to use blitz_0.9

I down load blitz_0.9,I can build it in vs2008 and get blitzd.lib and blitz.lib but how can i get blitz.dll who have used it give me some advice thank you. ...