c++

How do you declare an object of a class before the class is created in C++?

Is there anyway to declare an object of a class before the class is created in C++? I ask because I am trying to use two classes, the first needs to have an instance of the second class within it, but the second class also contains an instance of the first class. I realize that you may think I might get into an infinite loop, but I act...

Converting Reverse Polish Notation

Is there any way to interpret Reverse Polish Notation into "normal" mathematical notation when using either C++ or C#? I work for an engineering firm, so they use RPN occasionally and we need a way to convert it. Any suggestions? ...

Class library with support for several persistence strategies

I am developing a C++ class library containing domain model classes, and I would like to add support for instantiating these classes from various persistence mechanisms, i.e. databases and file. The user of the class library should be given an interface(?) against which to program a class that can transfer the data from/to the persistenc...

Performance penalty for working with interfaces in C++?

Is there a runtime performance penalty when using interfaces (abstract base classes) in C++? ...

C++ Binary operators order of precedence

In what order are the following parameters tested (in C++)? if (a || b && c) { } I've just seen this code in our application and I hate it, I want to add some brackets to just clarify the ordering. But I don't want to add the brackets until I know I'm adding them in the right place. Edit: Accepted Answer & Follow Up This link has mo...

What is a performant string hashing function that results in a 32 bit integer with low collision rates?

I have lots of unrelated named things that I'd like to do quick searches against. An "aardvark" is always an "aardvark" everywhere, so hashing the string and reusing the integer would work well to speed up comparisons. The entire set of names is unknown (and changes over time). What is a fast string hashing algorithm that will generate s...

Pointer vs. Reference

What would be better practice when giving a function the original variable to work with: unsigned long x = 4; void func1(unsigned long& val) { val = 5; } func(x); or: void func2(unsigned long* val) { *val = 5; } func2(&x); IOW: Is there any reason to pick one over another? ...

Boost shared_ptr container question

Let's say I have a container (std::vector) of pointers used by a multi-threaded application. When adding new pointers to the container, the code is protected using a critical section (boost::mutex). All well and good. The code should be able to return one of these pointers to a thread for processing, but another separate thread could ...

Difference between managed c++ and c++

The topics title is actually my question. And the second question is: When do I use what of these two? ...

how get a vector<Derived*> into a function that expects a vector<Base*> as argument

Hi, Consider these classes, class Base { ... }; class Derived : public Base { ... }; this function void BaseFoo( std::vector<Base*>vec ) { ... } And finally my vector std::vector<Derived*>derived; I want to pass derived to function BaseFoo, but the compiler doesn't let me. How do I solve this, without copying the whole vector...

socket listen backlog parameter, how to determine this value?

How should I determine what to use for a listening socket's backlog parameter? Is it a problem to simply specify a very large number? ...

Problem with converting enumerations in C++\CLI

I have an assembly, written in C++\CLI, which uses some of enumerations, provided by .Net. It has such kind of properties: property System::ServiceProcess::ServiceControllerStatus ^ Status { ServiceControllerStatus ^ get() { return (ServiceControllerStatus)_status->dwCurrentState; } } it works fine,...

Good C++ GUI library for Windows

I'm looking for good windows GUI library for C++. The Ideal in my opinion shoud be: Modern. MFC, wxWidgets, Qt were started a long time ago and they don't use modern C++ features and standard library. Have a rich set of controls with decent features. The ability to drop HTML almost everywhere is a happiness for which I love wxWidgets ...

Test Automation with Embedded Hardware

Has anyone had success automating testing directly on embedded hardware? Specifically, I am thinking of automating a battery of unit tests for hardware layer modules. We need to have greater confidence in our hardware layer code. A lot of our projects use interrupt driven timers, ADCs, serial io, serial SPI devices (flash memory) etc.. ...

Storing C++ template function definitions in a .CPP file

I have some template code that I would prefer to have stored in a CPP file instead of inline in the header. I know this can be done as long as you know which template types will be used. For example: .h file class foo { public: template <typename T> void do(const T& t); }; .cpp file template <typename T> void foo::do(const...

Pointers and containers

We all know that RAW pointers need to be wrapped in some form of smart pointer to get Exception safe memory management. But when it comes to containers of pointers the issue becomes more thorny. The std containers insist on the contained object being copyable so this rules out the use of std::auto_ptr, though you can still use boost::sh...

What is the best way to slurp a file into a std::string in c++?

How to slurp a file into a std::string, i.e., read the whole file at once? Text or binary mode should be specified by the caller. The solution should be standard-compliant, portable and efficient. It should not needlessly copy the string's data, and it should avoid reallocations of memory while reading the string. One way to do this wou...

Framework to bind object properties to WTL controls

I would like to have something like this: class Foo { private: int bar; public: void setBar(int bar); int getBar() const; } class MyDialog : public CDialogImpl<MyDialog> { BEGIN_MODEL_MAPPING() MAP_INT_EDITOR(m_editBar, m_model, getBar, setBar); END_MODEL_MAPPING() // other methods and message map private: Foo * m_mod...

Cleaning a string of punctuation in C++

Ok so before I even ask my question I want to make one thing clear. I am currently a student at NIU for Computer Science and this does relate to one of my assignments for a class there. So if anyone has a problem read no further and just go on about your business. Now for anyone who is willing to help heres the situation. For my curren...

Fastest way to see how many bytes are equal between fixed length arrays.

I have 2 arrays of 16 elements (chars) that I need to "compare" and see how many elements are equal between the two. This routine is going to be used millions of times (a usual run is about 60 or 70 million times), so I need it to be as fast as possible. I'm working on C++ (C++Builder 2007, for the record) Right now, I have a simple: ...