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

learn more… | top users | synonyms

28
votes
1answer
2k views

How does the C++ standards committee test their design ideas?

Does the C++ committee test their new design specifications with some sort of prototype compiler before releasing a new standard? Or do they release a standard which is, in effect, only theoretical ...
3
votes
1answer
515 views

In my situation, how could I learn to program without a mentor? [closed]

So my problem may be relatively rare, at least the majority of the "how to learn to code" questions I've come across deal with a lack of fundamental understanding of computers or languages. I'm fluent ...
5
votes
4answers
320 views

Why is there a need for reference parameters in C++?

We've been learning about reference parameters in my Intro to Programming class. I understand perfectly that reference parameters give you access to the place where an argument is held in memory, ...
61
votes
13answers
31k views

What's the benefit of object-oriented programming over procedural programming?

I'm trying to understand the difference between procedural languages like C and object-oriented languages like C++. I've never used C++, but I've been discussing with my friends on how to ...
0
votes
1answer
395 views

Recommendations to organize code changes in GIT

I'm looking for an advice reflecting my point of view. First, I will explain my point of view. My point of view I'm working in a big company as a C++ developer, we are using GIT. I'm going to make a ...
5
votes
4answers
760 views

Does making a method static save memory on a class you'll have many instances of?

In response to Aaronaught's response to the question at: Can't I just use all static methods? Isn't less memory used for a static method? I am under the impression that each object instance carries ...
2
votes
3answers
422 views

Is it bad practice to use Inheritance to associate methods with a basic container?

Basically, I have code that looks like this. It's a typedef and a set of methods that revolve around that typedef. class foo { // Foo stuff... // Registration Stuff private: ...
13
votes
6answers
7k views

Is it practical to abandon STL in C++ development? [closed]

I know in some areas (game industry, for example), STL is not recommended. So my question is: is it really a good practice not to use STL in some cases? If so, what's the biggest reasons of not using ...
0
votes
2answers
174 views

How to organize and label methods intended for debug?

I have a class System, which uses a bunch of other classes, to achieve some complex signal processing. In debugging System, one needs to observe the output signal for patterns. This is not achievable ...
1
vote
1answer
94 views

Analyzing a C++ library with a diagram [closed]

When I want to read an entire library in C++ I start with class A. Then I realize class A is using function B. Function B is using class C and C2 and class C uses class D. I am aware that this ...
1
vote
3answers
203 views

Is storing pointer (of new'd object) in static collection from object constructor a common idiom in C++

I am reviewing an approach I see commonly used in storing objects (e.g. a socket client object). Namely, usage of a static container to hold the objects. Said objects are created by some helper ...
2
votes
0answers
114 views

Speed: Named Shared Memory vs Memory Mapped File vs Normal Memory

Let's say I have a server, where clients who connect are constantly updating their inventory. I could simply save the changes in to the database after an item has been updated, or I could update the ...
2
votes
2answers
3k views

How to see bits of an integer in Visual Studio [closed]

As far as I know it is not possible to see the bits of an integer in Visual Studio, you can see variables in decimal or hexadecimal format in the Locals and Watch windows in the debugger. Why is this ...
0
votes
1answer
161 views

Kernel facilities needed for C++

I'm working on a kernel for a proprietary embeded system. I've had no issues but I'd like to expand its capabilities directly. I made it run C. I did so pretty much by giving my kernel a stack. My ...
25
votes
1answer
11k views

C++11 includes std::stoi, why not std::itos?

I noticed to my glee that C++11 has a std::sto@ family of functions for easily unpacking ints/floats/longs whatever from strings. I'm surprised however, that the opposite isn't implemented. Why didn't ...
2
votes
2answers
157 views

C++ object references vs. lookup

Let's assume there are 2 classes: Country and City. Both of them have names, so a map would suit as conainer map<std::string, Country> countries; In the country class there is a similar map ...
4
votes
2answers
307 views

Designing an in-memory table in C++

I'm evaluating my options to structure an in-memory database and I have a few ideas of how to implement it. I would like to know your opinion of what the best design choice is. I have a column class ...
7
votes
2answers
256 views

Object reading from file, violation of SRP?

I am writing a physics simulation program in C++. I am a novice in OOP and C++. In my program, several objects need to be initialized based on data from an input file. For example, an imaginary ...
4
votes
2answers
101 views

Accessing members of a set by one of their properties

I often find myself in the situation where an object contains a set of objects, and I want to access one of these objects based on one of its properties. How I currently do this in C++ is to put ...
2
votes
1answer
94 views

Best way to use a C++ style api from a C style file compiled in C++

I am working a in a Telecom company. We have some code generation tools that generate C style files based on a MIB definition. We compile them with C++ though. It boils down to the fact that these ...
4
votes
5answers
685 views

Why does integer division result in an integer?

We learned in Intro to Programming that if you divide two integers, you always get an integer. To fix the problem, make at least one of those integers a float. Why doesn't the compiler understand I ...
1
vote
1answer
173 views

Destructing an object of a class correctly

I have a scenario, where I draw multiple graphs in same applications and each graph is an object of graph class. I want to delete the graph using event handling (button click event) and the event ...
1
vote
1answer
158 views

In C, are large 'pointer chains' bad for performance or code cleanliness?

The following for example: i = readString(&packet->data.play_server.updatesign.line1, pbuf, ps); It has a large amount of nested structs/unions. Is this generally frowned upon in code ...
4
votes
1answer
204 views

How to Structure Simple C++ projects for TDD

I am introducing Google Test into our development environment at work, and would like to encourage a TDD mindset, making this as accessible as possible for new developers to start using. I am looking ...
1
vote
2answers
121 views

C++ Parametric Polymorphism

In the wikipedia article on Parametric Polymorphism, is the following commentary on C++. Can anyone explain what it's referring to when talking about "ad hoc aspects"? (I think it needs a ...
95
votes
13answers
15k views

Should we avoid language features that C++ has but Java doesn't to increase maintainability?

Suppose I am limited to use C++ by the environment in the project. Is it good to prevent the use of some language features that C++ has but Java doesn't have (e.g.: multiple inheritance, operator ...
5
votes
4answers
520 views

Is it a good idea to document every assumption in code, even if it goes against the standard of the language?

For instance, would this c++ function be a good idea? void doSomething(not_nullptr<MyType> arg) { // stuff } With not_tullptr being a template wrapper for pointers, that will throw an ...
2
votes
0answers
44 views

How to architect rule matching with multiple conditionals and outcomes

I'm working on allowing my users to create their own ruleset for data that's coming in. All of the data below is sample mock data and not in relation to our product. Example of a rule (there can be ...
-4
votes
2answers
126 views

Repeating a Particular Iteration of For-Loop [closed]

I want to repeat a particular iteration of a for loop twice. The way I am doing it is that I am decrementing the index in that particular iteration. for(int i = 0; i < 100; i++) { ...
3
votes
1answer
318 views

Bad c++ code design? [closed]

This is bothering me a long time. I feel like I am doing mistakes on the code design relative to the performance. I never had any teacher to indicate my mistakes so its hard to me to make it right in ...
1
vote
1answer
173 views

Data structure to use for time-optimized line-vs-grid check?

I am asking here because I feel that this question can be filed under the "algorithm and data structure concepts" category. Background: I have been recently assigned the task to design and develop a ...
0
votes
1answer
72 views

Blocking queue for token based synchronization

I'm currently looking for a good solution for the following use-case in C++ (preferably C++11 or C++14): The program is running a server with a TCP connection. Other clients can connect at any time ...
2
votes
1answer
126 views

What is an appropriate pattern for handling a queue of network events in C++?

I'm writing an application that sends and receives messages over the network and pushes them into a std::deque queue. and I'm looking for the appropriate programming pattern to handle all of the ...
2
votes
2answers
127 views

Abstraction on Iterator Pattern?

Recently, I had the task to implement a research project where I had to read an XML file. XML file contained a list of messages that I had to send to some other system on a specific port. Each message ...
37
votes
9answers
7k views

Explanation on how “Tell, Don't Ask” is considered good OO

This blogpost was posted on Hacker News with several upvotes. Coming from C++, most of these examples seem to go against what I've been taught. Such as example #2: Bad: def ...
21
votes
3answers
6k views

Why is C++ predominant in programming contests and competitions? [closed]

I understand that C++ is a very fast language, but ain't C just as fast, or faster in some cases? Then you might say that C++ has OOP, but the amount of OOP you need for most programming puzzles is ...
0
votes
4answers
391 views

Are there reasons to assign NULL instead of 0 to non-pointer variables?

Assigning variables with values during definition is a good practice. A common practice is to assign variables with 0 and pointers with NULL. int p = NULL; // instead of int p = 0; int *ptr ...
2
votes
2answers
265 views

Error handling in C++

So, in the recent weeks I delved into C++ programming, and I programmed some things in SDL. Doing so, you always have to deal with a lot of (ugly) C++ code, which looks more like C than C++. One thing ...
-1
votes
1answer
98 views

SDL_net how to get the UDP remote address? [closed]

I have a problem with the tcp and udp synchronization. On the server it accepted the tcp connection with the: SDLNet_TCP_Accept(); But now I need to know how to get the remote address of the ...
3
votes
4answers
143 views

Low-level error handling

I am working with some low-level (by that I mean code that can't use C++ exceptions and/or the standard library) code that makes heavy use of classes. Basically, every class contains a bool ...
-1
votes
3answers
186 views

How are expressions evaluated in Turbo C++?

I was reading about casts in c++ and got confused about how are the expressions actually evaluated. Consider the following code in which var is of type int and after the expression var = (var*10)/10 ...
0
votes
3answers
22k views

2 Dimensional Arrays in C++

I started learning arrays in C++ and came over a little side note in the book talking about 2D arrays in breif. I tested it out and i was amazed that it could give the programmer the ability to store ...
4
votes
2answers
148 views

Free-standing function calling a state-changing member function — a bad practice?

Item 23 of Effective C++ (3rd edition) by Scott Meyers is titled: "Prefer non-member non-friend functions to member functions". I understood that the intention of Scott was that, whenever a function ...
5
votes
1answer
131 views

Member vs. free-standing functions with respect to interface uniformity

Item 23 of Effective C++ (3rd edition) by Scott Meyers is titled: "Prefer non-member non-friend functions to member functions". The reason Scott suggests is the increase of encapsulation. So, only the ...
-2
votes
2answers
214 views

How can a software code be made modifiable without being visible to the end user?

I wish to supply a software product with GUI, etc. for operating it. And the software utility is research so the users will want to tweak it to some extent and implement their own preferred algorithms ...
33
votes
9answers
6k views

Is the algorithm more important than the programming language?

During the current (2013) Google Code Jam contest, there was a problem that took C++ and Java people 200+ lines of code as compared to Python people that solved the same problem only using 40 lines of ...
1
vote
3answers
140 views

Do methods Merge and Join make sense for a path class?

I'm writing a path class which currently has a method called Combine which works like the .NET Path.Combine. If an argument is an absolute path (roughly because it begins with \), then it replaces ...
10
votes
1answer
771 views

Object lifetime invariants vs. move semantics

When I learned C++ long ago, it was strongly emphasized to me that part of the point of C++ is that just like loops have "loop-invariants", classes also have invariants associated to the lifetime of ...
0
votes
0answers
100 views

What to unit-test when loading a dll?

I wrote a wrapper class that is using a dll. I have a LoadLibrary() function and have wrapped all the functions the dll exports (to match my error codes). I am not too familiar with unit testing. I ...
7
votes
2answers
313 views

Compile-time checking for NULL initialized std::string

This is sort of the complementary question to How to best protect from 0 passed to std::string parameters?. Basically, I'm trying to figure out whether there is a way to have the compiler warn me if a ...