Questions about C++, a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.

learn more… | top users | synonyms

63
votes
16answers
11k views

Do I really need oop for my kind of job? After 10 years I think I don't [closed]

After 10 years of writing something like business logic for my company I realized that for 95% of my code I just don't need any special OO techniques. For years I tried to get better with all that OO ...
3
votes
4answers
4k views

Fast compression in C++ and decompression in C#

Overview I am working on a client-server application. The client is written in C++ (working on Windows, planning to support Linux) and the server is a .NET RESTful service. I need to HTTP POST some ...
1
vote
3answers
629 views

Is this Observer variant an improvement?

In a C++ code base I've been working on, they have a bunch of instances of the observer pattern, but it's a little different from the classical pattern. In the classic, the Observer is a specific ...
3
votes
2answers
316 views

What happens when using address before it's allocated?

The very simple piece of C++ code below is incorrect, it's easy to see why and tools like Valgrind will tell you. In running several C++ codes containing this kind of error, I noticed that each time, ...
5
votes
4answers
781 views

Is it possible to create a 2d game for both linux and windows with next to no changes?

I'm starting a project with friends which would preferably reach both audiences of windows and linux. The only problem is that none of us have any experience of linux porting or linux coding any way. ...
0
votes
2answers
196 views

Is there anything special to consider when writing my own exception class in C++? [closed]

If I wanted to implement my own version of the std::exception for no good reason, are there any special things about implementing this kind of object that I should be aware of? It seems like a fairly ...
18
votes
4answers
1k views

Detecting misusage of delete[] vs. delete at compile time

I'd like to know if it's possible to detect the delete error commented below at compile time? Especially, I'd like to hear about g++ compiler. ClassTypeA *abc_ptr = new ClassTypeA[100]; ...
6
votes
3answers
965 views

A question regarding linked list vs vector insert/remove results comparison

I was reading this blog post: http://kjellkod.wordpress.com/2012/02/25/why-you-should-never-ever-ever-use-linked-list-in-your-code-again/ and I found there a code to run: http://ideone.com/62Emz ...
1
vote
1answer
345 views

Is this an implementation of the promise pattern?

I am writing a library in C++ (making use of many C++11 features) that (as far as I can tell) implements the promise pattern. The library consists of a class that makes asynchronous network requests. ...
1
vote
1answer
1k views

Environment Variables and Visual Studio 2012

I have a problem with Visual Studio 2012 and Environment Variables under Windows 7. I added a variable called {LIBS} with the value C:/libs/. In C:/libs/ are folders containing C++ libraries. So far, ...
1
vote
2answers
218 views

Would it be bad design to abstract a graphics library and wrap it in a single class? [duplicate]

I'm starting a game project in C++ using the SFML. It provides various classes for handling graphics, input, etc, but I would like to wrap it all up in a single Media class. I believe that by doing ...
0
votes
3answers
280 views

C/C++ in applications that do not concern performance [closed]

C is the best language (or maybe the single language) suitable for operating systems, drivers, embedded systems etc. For more complex domains like computer graphics C++ is a better choice. But these ...
7
votes
1answer
2k views

Is C a regular language?

Are C or C++ regular languages? If not, under which category do we place the programming languages like C/C++, perl, Python?
2
votes
3answers
2k views

When do you 'speak' C++ fluently? [closed]

I see that many companies require the same skill. This skill is often described as following: "Applicants are required to speak C++ fluently." I never really understand what fluent meant for ...
2
votes
1answer
1k views

3d point cloud render from x,y,z 2d array with texture

Need some direction on 3d point cloud display using OpenGL in c++ (vs2008). I am brand new to OpenGL and trying to do a 3d point cloud display with a texture. I have 3 2D arrays (each same size ...
3
votes
3answers
1k views

What is the necessity to go for lambda functions and expressions in C++?

What is the necessity to use lambda functions and expressions in C++? Can you explain or show through examples how to use lambda functions and expressions? I already gone through the related ...
0
votes
3answers
4k views

Should I learn in c++ or c# (for computer science degree)? [closed]

I'm about to start a "Bachelors of Science (Computer Science)" degree (in Australia, semester starts in march) and I'm presented with the option to learn c# or C++. First of all, I already know C#, ...
32
votes
10answers
3k views

Difference between Idiom and Design Pattern?

What is the difference between idiom and design-pattern? It seems that these terminologies overlap somewhere; where exactly, I don't know. Are they interchangeable? When should I use what? Here is a ...
7
votes
4answers
796 views

Design pattern for polymorphic behaviour while allowing library separation

Let's say I have a hierarchy of Item classes: Rectangle, Circle, Triangle. I want to be able to draw them, so my first possibility is add a virtual Draw() method to each: class Item { public: ...
4
votes
1answer
1k views

sqrt c# vs sqrt c++

An idea why the c# version of sqrt (System.Math.Sqrt) is ~10 times slower than c++ version ? Futhermore, C# version seems to have one extra digit of precision. I have run my test under MSVC2012. I ...
11
votes
2answers
2k views

How does C++ handle multiple inheritance with a shared common ancestor?

I'm not a C++ guy, but I'm forced to think about this. Why is multiple inheritance possible in C++, but not in C#? (I know of the diamond problem, but that's not what I'm asking here). How does C++ ...
7
votes
2answers
2k views

Using a stream manipulator (endl) or a newline escape character (\n)?

I don't have a specific context in which I'm asking the question, but while I was reading a beginner book on C++ I noticed the use of both an endl stream manipulator and a newline escape character ...
1
vote
2answers
4k views

Using the STL to solve interview questions? [closed]

If I'm undergoing a technical interview that's based on my C++ skills, would most companies allow or expect me to use STL containers to solve problems? I think it's clear that if a question is ...
4
votes
6answers
9k views

What is a 'Null Terminated String' ?

I have just started reading C++, and I came across a term "Null Terminated String", I read about it but couldn't understand what it actually stands for. I also want to know what is the difference ...
4
votes
2answers
207 views

Non-lvalues as function parameters in C++

I'm reading Accelerated C++ and in Chapter 4 they bring up the concept of lvalues. There's an example of something that shouldn't work, but after trying it myself I found that it does indeed work. ...
5
votes
4answers
852 views

Is there something like a polymorphic Singleton?

I have a resource loader object that loads objects from the disk or from a ZIP archive, depending on the platform. It has state (e.g. the path to the directory or the ZIP archive, and possibly some ...
4
votes
4answers
235 views

What performance topics should I be aware of? [closed]

When coding performance-critical portions of code (not necessarily large, but code that gets executed a lot), what topics should I be aware of/take into account. I'm already fairly familiar with ...
2
votes
1answer
439 views

Where did the T in wchar_t come from?

In many native types, a common suffix (and sometimes prefix) of t or _t is used to denote platform-independent types (such as wchar_t, int32_t, etc.) What was the logic behind the letter t as opposed ...
-1
votes
1answer
2k views

Fastest native C++ multi-platform compiler & IDE & debugger [closed]

If I'll begin developing cross platform applications, The complied file speed is very important for me . I have research before than and find same result about IDE : (I ignored eclipse because very ...
22
votes
2answers
2k views

What does it mean to expose a C++ code publicly as a C API and what are the advantages of doing it?

I often hear people say that C++ programmers should expose their library's/product's public API as a C API. What does that mean and what are the advantages of that?
18
votes
3answers
3k views

Did C++11 address concerns passing std lib objects between dynamic/shared library boundaries? (ie dlls and so)?

One of my major complaints about C++ is how hard in practice it is to pass std library objects outside of dynamic library (ie dll/so) boundaries. The std library is often header-only. Which is great ...
0
votes
3answers
3k views

How to become an expert in C++ [closed]

I have some experience in Java programming and enterprise application development. I have done OOP, data structures in C++ for my undergraduate studies. But I couldn't touch C++ for years. Now I am ...
3
votes
1answer
1k views

C++ on Windows vs Linux - common issues? [closed]

So far all my development in C++ has been targeted to Windows, however I have always had it in the back of my mind that I will someday be targeting Linux. I am aware therefore of the need to select ...
4
votes
1answer
324 views

How does a priority_queue maintain a heap on a deque efficiently?

In the C++ STL, priority_queue (heap) can be used with any underlying container, such as a deque. How does the implementation stay O(log n) if deques don't swap an item in index a with index b in ...
12
votes
6answers
541 views

OO Design, how to model Tonal Harmony?

I have started to write a program in C++ 11 that would analyse chords, scales, and harmony. The biggest problem I am having in my design phase, is that the note 'C' is a note, a type of chord (Cmaj, ...
6
votes
3answers
2k views

How do you handle increasingly long compile times when working with templates?

I use Visual Studio 2012 and he have cases where we added templates parameters to a class "just" in order to introduce a "seam point" so that in unit-test we can replace those parts with mock objects. ...
1
vote
2answers
308 views

c++ exceptions vs. preliminary error condition checks

Preamble One of the concepts used in writing Python code is "Easier to ask for forgiveness than permission", aka EAFP. Literally this means that instead of doing checks, whether an operation is ...
8
votes
7answers
1k views

Is Java much harder to “tweak” for performance compared with C/C++?

Does the "magic" of the JVM hinder the influence a programmer has over micro-optimisations in Java? I recently read in C++ sometimes the ordering of the data members can provide optimizations ...
3
votes
1answer
587 views

How to structure unit testing of huge libraries?

I am writing unit tests for a library written in Qt/C++. The library is rather big, with lots of functionalities. I have a separate unitTest folder which I have my UnitTest.cpp in there. Having all ...
69
votes
3answers
14k views

Is C++11 Uniform Initialization a replacement for the old style syntax?

I understand that C++11's uniform initialization solves some syntactical ambiguity in the language, but in a lot of Bjarne Stroustrup's presentations (particularly those during the GoingNative 2012 ...
3
votes
4answers
1k views

Good design pattern for a c++ wrapper around a c object

I have written an extensible c++ wrapper around a very hard to use but also very useful c library. The goal is to have the convience of c++ for allocating the object, exposing its properties, ...
40
votes
12answers
2k views

Which C# practices should be avoided in C++?

I'm currently teaching myself C++. I'm very proficient at C#, and was wondering which common practices in C# can lead to difficulties in C++, and what a C++ programmer should do instead.
4
votes
4answers
642 views

Having error codes option in C++ library for performance

I have written an open source and cross-platform C++ File Library which have exception and error codes. Exceptions can be disabled when the program is running. In that case, the user have to check the ...
0
votes
1answer
411 views

Increase the size of a memory mapped file

I am maintaning a memory mapped file to store my tree like datastructure. When I'm updating the datastructure ,I got this problem. The file is limited on it's size and can't be too long or too small. ...
5
votes
3answers
1k views

C++ name mangling and linker symbol resolution

The name mangling schemes of C++ compilers vary, but they are documented publicly. Why aren't linkers made to decode a mangled symbol from an object file and attempt to find a mangled version via any ...
6
votes
1answer
296 views

Difference between language virtual machine and emulating vm?

I'm having a hard time understanding the difference between an emulation virtual machine and a language vm. I started with the research and implementation of an emulation virtual machine. Primarily ...
3
votes
2answers
854 views

Memory management for fast message passing between threads in C++

Suppose there are two threads, which communicate by asynchronously sending data messages to each other. Each thread has some kind of message queue. My question is very low level: What can be expected ...
15
votes
5answers
8k views

JIT compiler for C, C++, and the likes

Is there any just-in-time compiler out there for compiled languages, such as C and C++? (The first names that come to mind are Clang and LLVM! But I don't think they currently support it.) ...
4
votes
2answers
319 views

What is the lifecycle for loading a Linux Desktop Environment?

I'm looking into delving into a bit of custom OS work (and yes I understand that doing any development at the DE level or lower on an OS is extremely complex and not a light thing to undertake, ...
16
votes
1answer
2k views

Motivation and pitfalls (?) of the auto keyword in C++11

I was recently wondering why the keyword auto was chosen in C++11 to mark a variable whose type must be inferred by the compiler, like in auto x = 1; Since var seems more common in other ...