c++

How to validate that some template does *not* compile for given argument types?

I'm writing a smart ptr template which is intended to be instantiated only for a given base class and its subclasses, which provides boost::shared_ptr-like implicit conversions to variants MyPtr<U> of the template MyPtr<T> has long as the conversion is valid from T* to U* (valid base class and const-compatible). This was working fine in...

Mapping from character id to a class name in c++ via templates?

Duplicate: http://stackoverflow.com/questions/582331/c-is-there-a-way-to-instantiate-objects-from-a-string-holdig-their-class-name Is there a (better) way in C++ to map string id to a class name. I suspect there might be a way via templates but I wasn't able to figure out the correct way. For example if I have multiple messages, each...

CGAL inheritance

How can I use an inherited class of a triangulation in the context of a triangulation in CGAL? Basically I have the following code: typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Triangulation_vertex_base_with_info_2<int,K> Vb; typedef CGAL::Triangulation_face_base_with_info_2<int,K> Fb; typedef CGAL::T...

C++ Equivalent to Designated Initializers?

Recently I've been working on some embedded devices, where we have some structs and unions that need to be initialized at compile time so that we can keep certain things in flash or ROM that don't need to be modified, and save a little flash or SRAM at a bit of a performance cost. Currently the code compiles as valid C99, but without th...

C++: First element of vector "corrupting"

I have a class (foo) that contains a vector. If i try iterating over the elements in the vector like so: for(vector<random>::iterator it = foo.getVector().begin(); it != foo.getVector().end(); ++it) { cout << (*it) << endl; } The first element is always corrupted and returns garbage data. However, if do something like: ...

Why is it necessary to add new events to the *end* of an IDL interface?

I have found that when I add new events to an existing COM/IDL interface, I sometimes run into strange issues unless they are added to the end of the interface. For example, say I have the following interface: interface IMyEvents { HRESULT FooCallback( [in] long MyParam1, [in] long MyParam2, [in] long MyPara...

How to build a c++ project on a remote computer in Eclipse?

I have a Windows pc with Eclipse Ganymede installed, and a Linux pc where my C++ project files are located. I use Eclipse to edit the files through SMB, and would like to build the project using Eclipse as well. Currently I connect using putty to my linux machine, and run ./make from the appropriate directory. How would I run the same co...

How to remove/delete executable files (aka files without extension) only

I have a directory src/ that contain many .cc files and its binary. For example: src/ |_ foo.cc |_ bar.cc |_ qux.cc |_ thehead.hh |_ foo (executable/binary) |_ bar (executable/binary) |_ qux (executable/binary) |_ makefile In reality there are many .cc and executable files. I need to remove those binaries in a glob...

Very strange visual studio behaviour with excessive lines of whitespace

Hi, yesterday we updated to a new version of some middleware we are using, and had a very bizarre merge problem with perforce... it had created approximately 10-20 thousand lines of white space in one of my functions, this all compiled fine, upon running the program it crashed indicating some memory issue, tracing back through the call s...

Elegant solution to duplicate, const and non-const, getters?

Don't you hate it when you have class Foobar { public: Something& getSomething(int index) { // big, non-trivial chunk of code... return something; } const Something& getSomething(int index) const { // big, non-trivial chunk of code... return something; } } We can't implement either of t...

C++ Library requires LibCurl - will users of the app need libcurl?

Hello, I'm normally a Java developer, but I'm writing a C++ library right now they will use LibCurl. And I'm very un-aware in the C++ world! What I'm writing is infact a library for use by other developers (its a client code used to access our API). Will end users be required to have libcurl installed, or can the developers somehow in...

C++ Converting a Datetime String to Epoch Cleanly

Is there a C/C++/STL/Boost clean method to convert a date time string to epoch time (in seconds)? yyyy:mm:dd hh:mm:ss ...

xcode gives syntax error on cpp code

I am trying to reuse Apple's Speak Here sample code in my own iPhone app. I downloaded and compiled the project with no problems, so I then added some of the files to my own application. When I try to compile my own application, the compiler gives me MeterTable.h:54: error: syntax error before 'MeterTable' The relevant code is: #inc...

C++ namespace problem with ARM RealViewICE

I'm using ARM RealView debug 3.1 and I'm unable to watch variables inside functions defined in a C++ namespace, the code works well and is compiled with armcc. Do any of you know a solution for this? ...

Refresh Window in Visual C++

I've a Visual C++ project but I don't be able to refresh the window and redraw itself. I've used RedrawWindow(); m_ProgressDlg->RedrawWindow(); and also UpdateData(false); m_ProgressDlg->UpdateData(false); but never seems go well. How can I do? ...

Compiler generated code in code coverage

I am using Intel code coverage tools on Linux using g++ compiler. For a particular class, the coverage tool shows 2/3 extra functions than those actually present in source code. What are these extra functions? Are they compiler generated functions? I am excluding header files from code coverage. My classes are simple with empty ctor an...

Can I iterate over the elements that are in one range of iterators but not in another?

Let's say I have a sequential container, and a range (pair of iterators) within that container of elements that are currently 'active'. At some point, I calculate a new range of elements that should be active, which may overlap the previous range. I want to then iterate over the elements that were in the old active range but that are not...

What is the most correct way to hide an autocomplete popup?

I'm developing a custom autocomplete control in pure WinApi, and the problem that I've encountered is that I don't know how to hide the popup window when clicked outside of the control (e.g. emulate the combobox dropdown behavior). How is it usually implemented? Should I use mouse capture? Thanks. UPD: Tracking keyboard focus doesn't fi...

Calling overridden function from the overriding function

Suppose I have virtual function foo() in class B, and I need slightly different behavior in one of B's derived classes, class D. Is it OK to create an overriding function D::foo(), and call B::foo() from there, after the special case treatment? Like this: void D::foo() { if (/*something*/) // do something else B::foo(); } ...

How to handle messages from dynamically created controls in an MFC app?

Imagine I have a CDialog which creates controls dynamically when the user clicks a button. It could be like this: // We don't know which is the first id for the new buttons until runtime (!) MyDialog::MyDialog(/*whatever parameters needed*/, first_id) : next_id_(first_id) { /*...*/ } BOOL MyDialog::OnSomeButtonClicked() { CButton*...