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

learn more… | top users | synonyms

1
vote
2answers
299 views

Drawback of mixing C++ code with C for performance purposes

Often you can see answers like “Avoid using C libraries in your C++ code“ or “This can be rewritten using STD/Boost in pure C++“. I understand C++ produces more maintainable code and has many ...
0
votes
1answer
213 views

How to maintain view logic separation with a server

I am writing a client server application. I wanted to fully separate the server logic, from the view. The first thing I wanted to to, is to make a sort of a message log. The server itself should not ...
2
votes
6answers
414 views

Nested Classes or Namespace

Why do need namespaces when we have nested classes. What can be done through namespaces, can also achieved through nested classes. so I don't understand the reasoning of having namespaces ?
5
votes
1answer
423 views

Using std::sort et al. with user-defined comparison routine

In the evaluator of a custom language, I would like to replace our own sort routines with std::sort or other routines, possibly tbb::parallel_sort. The problem is that we allow users of the language ...
5
votes
5answers
645 views

Teaching a course on intro to programming, in C++: Do I teach C-style casts? [closed]

I'm currently redesigning a college level first semester graduate course on Intro to Programming, in C++. Note the comma; the course is introduction to programming, and C++ just happens to be the ...
2
votes
3answers
222 views

How to evaluate CLR / C++ vs native C++?

How should I go about evaluating the performance or execution time of C++ with CLR versus native C++? My personal bias is that I believe C++ with CLR to be slower since it has to run on a virtual ...
6
votes
2answers
878 views

Calculator with 3+ values

I am new to c++ and have been making the good old Calculator. I have gone forward from a 2 value calculator to a 3 value calculator and wondered.. How is it possible to make a 10 digit calculator ...
2
votes
3answers
186 views

How to avoid binary dependency on size change

class A { public: int i; }; // A.h and defined in project libA.vcxproj (libA.dll) I'm using class A in multiple places at various projects as below. Apporoximately 100 projects. include "A.h" class ...
2
votes
1answer
332 views

Which is better to use? (Enum or Constant)

I have my enum like this. enum Size{PAGE_SIZE=20, HEADER_SIZE=30 }; I only use them as constants(No enum variable created) in my program. i.e= int x = PAGE_SIZE + 20; So what is the ...
3
votes
2answers
272 views

What format is the data going to Windows print drivers?

I have been tasked with writing a print driver. I have no experience with this and have been researching it for a few days. The goal of this is to essentially write the data coming to the driver to ...
5
votes
4answers
325 views

Preventing a parser from turning into a (seemingly) god-sized object

So I have a program whose purpose is to take text files and parse them into a binary format that an embedded system understands. However, the text format I've inherited that I need to parse is ...
3
votes
2answers
542 views

How to represent a geometric line programmatically?

I have been trying to design a library to do some simple geometric computations in an Euclidean space regardless of its dimension. While it is easy to represent points, vectors, hyperspheres and ...
2
votes
3answers
200 views

How to simulate and estimate long running application [closed]

We are building a large, modular application that is intended to run across multiple processors. I need to develop a method to estimate how long it will take to run all of the functions. I already ...
1
vote
3answers
361 views

Plain old struct vs class in this case?

Stroustrup says that you should use structs unless you can specify an invariant for the data structure. I have to represent a physical object which holds things such as position, velocity, mass and ...
2
votes
1answer
227 views

Any programming languages that support Generics exclusively and have no OOP support? [closed]

I am writing a paper on the tension between OOP and Generic programming created by Stepanov. He widely criticizes OOP and says it is "technically flawed" when compared to Generic Programming. Now I ...
2
votes
2answers
524 views

Concrete types - as described by Stroustrup - C++ Programming Language 4th ed

I'm having a hard time with this concept. What is Stroustrup getting at here? What is special about a class whose "representation is part of its definition"? What does a "concrete type" contrast ...
2
votes
2answers
200 views

How to refactor out static members of basic classes

Currently I am working on C++ project, which can be classified as "legacy" project. A lot of poor written code was committed because of lack of experience and under the pressure of deadlines. When I ...
6
votes
3answers
697 views

Faster reads, on an infinite grid plane, than using a hash table?

In the past, I've had alot of success just using a .NET Dictionary, with a TKey consisting of the X,Y coordinates merged together. However its read performance, despite being amortized constant time, ...
8
votes
2answers
333 views

Unit testing side effect-heavy code

I'm starting to write C++ code to run a robot, and I don't know how to incorporate unit testing, if indeed I can. I have been provided with a library which allows the creation of "commands" for the ...
23
votes
6answers
2k views

How is major software protected? [duplicate]

I am a new software developer and I wish to sell my software. I recently realized that from C++ code we can not stop the user seeing parts of the code that are related to scripts or system commands. ...
-1
votes
4answers
309 views

What exactly is my program “linking” with overall? [closed]

I have heard that my C++ programs "need to link with the C++ library/runtime". However, the C++ runtime is just the compiler inserting stack operation code in to the image, or "boilerplate" code if ...
14
votes
6answers
1k views

How to best protect from 0 passed to std::string parameters?

I have just realized something disturbing. Every time I have written a method that accepts a std::string as a paramater, I have opened up myself to undefined behaviour. For example, this... void ...
2
votes
2answers
473 views

Help me think in C++

I mainly use dynamic languages. For many years I see statically typed hello world examples like const int STACK_SIZE = 100; And I will think "wow, I can't think like that". I understand memory ...
1
vote
0answers
74 views

Representation of time expanded graph

I want to build a time expanded graph with time discretization Dt that starts at t = 0 and ends at t = T where between the node (n1, t) and the node (n2, t') is an arc if and only if (n1, n2) were ...
1
vote
4answers
320 views

Data duplication vs Encapsulating. Which design to use?

The problem that I face is how to combine encapsulating and optimal memory use. I can't show you my code and therefore explain it on extensive (I hope) example. Let's say we need to have a database ...
1
vote
2answers
311 views

How to choose a code style for C++ [closed]

When starting to learn one new language, we have to choose perfect code style such as types or file name's first letter should be uppercase or lowercase, etc. But when I started to learn C++, I did ...
1
vote
3answers
257 views

Better style for member variables?

class awesomeClass { std::list<A> myList; //... void fillList(); }; awesomeClass::awesomeClass() { fillList(); } void awesomeClass::fillList(){ //... foreach(A a, ...
0
votes
2answers
257 views

Difference between Singleton pattern and auto_ptr<> resp. unique_ptr<>

I'm maintaining some legacy code of a physical simulation. The calculation object is build as a singleton, to ensure there is only one instance. A co-worker told me, that singleton are completely ...
2
votes
1answer
290 views

Clearing the lowest set bit of a number

I can see in this tutorial on bit manipulation, under the heading "Extracting every last bit", that - Suppose we wish to find the lowest set bit of x (which is known to be non-zero). If we ...
0
votes
1answer
236 views

High Level Configuration of Constructor Injection in C++

My questions are specifically dealing with dependency injection through the constructor. I understand the pros/cons of service locator pattern, constructor/setter injection, and their flavors, however ...
0
votes
3answers
230 views

Add behavior without changing existing class

I have a class Container, which represents wrapper around std::list. This class contains following public methods: void add(Shape *item) void next() void setBegin() Shape* curr() and protected ...
3
votes
2answers
249 views

Intersection of geometric entities

I was trying to design a small C++ geometric API for learning purposes, but came across a problem when dealing with intersections of geometric entities. For example, the intersection of a line and a ...
1
vote
1answer
503 views

What is the difference between string.c_str() and &string[0]?

What are the differences between string.c_str() and &string[0]? Regarding performance my guess is that &string[0] is a little faster than string.c_str() as it doesn't require a function call. ...
1
vote
1answer
295 views

Language with syntactic sugar that translates to C++ that looks “hand-written”

I'm a college student and I have homework in C++. My professor wants separate hpp and cpp files for each C++ class. And it just didn't feel good how much I had to type, and how much I had to click to ...
4
votes
2answers
1k views

Dota 2 running on Linux, Mac and Windows - How do they do it?

How do Valve create games that run on Linux, Mac and Windows? I imagine they dont really write one version for each platform bec that would just be a nightmare.. or do they? I imagine it is written in ...
3
votes
1answer
280 views

Compiler doesn't inline anything?

I've rolled my own SIMD-accelerated math library. It's gotten pretty complete, so naturally I went to conduct speed tests and optimize it. Btw this isn't premature optimization, the lib is actually ...
1
vote
4answers
546 views

Why languages that compile to C/C++ generate unreadable, cryptic code?

I'm willing to compile certain language to C or C++ for some speedups. My idea was, though, to generate readable code and use structures such std::vector and similar wherever I can, expecting CLANG to ...
0
votes
1answer
155 views

Does changing the name of a namespace count as a MAJOR change in semantic versioning?

I'm writing a C++ library, and according to this site here: http://semver.org/, I should increment the MAJOR version when I make incompatible API changes. Is changing the name of a namespace ...
1
vote
3answers
1k views

How to ensure that a member variable is initialized before calling a class method

There's a class with a parametrized constructor that initializes a member variable. All public methods of the class then use this member variable to do something. I want to ensure that the caller ...
0
votes
1answer
193 views

Does C++ support subtyping?

I know it might be a silly question to ask, but I didn't quite get an a absolute clear answer on this matter, so I thought I'd put it here. Does c++ support the subtyping in the sense that it ...
5
votes
4answers
647 views

What's the reason exceptions are heavily used in managed (C# and Java) languages but not in C++? [closed]

AFAIK, a lot of C++ projects don't allow exceptions and deny them in coding guidelines. I have a lot of reasons, for example, exception is hard to handle correctly if your binary needs to be compiled ...
48
votes
12answers
3k views

Is it reasonable to null guard every single dereferenced pointer?

At a new job, I've been getting flagged in code reviews for code like this: PowerManager::PowerManager(IMsgSender* msgSender) : msgSender_(msgSender) { } void PowerManager::SignalShutdown() { ...
3
votes
2answers
234 views

Semantic coupling vs. large class

I have hardware I communicate with via TCP. This hardware accepts ~40 different commands/requests with about 20 different responses. I've created a HardwareProxy class which has a TcpClient to send ...
2
votes
1answer
777 views

Is it viable to make a port from a C++ application to Java through LLVM

how viable is it to port a C++ application to Java bytecode using LLVM (I guess LLJVM)? The thing is that we currently have a process written in C++ but a new client has made mandatory to been able ...
15
votes
5answers
789 views

“Whole-team” C++ features?

In C++, features like exceptions impact your whole program: you can either disable them in your whole program, or you need to deal with them throughout your code. As a famous article on C++ Report ...
1
vote
2answers
753 views

Storing a pass-by-reference parameter as a pointer - Bad practice?

I recently came across the following pattern in an API I've been forced to use: class SomeObject { public: // Constructor. SomeObject(bool copy = false); // Set a value. void ...
0
votes
5answers
2k views

Reference vs dereference pointers in arguments C++/C

OK, I'm facing this all the time in many functions I write, which should I use? void sth(int* a) void sth(int& a) Which one is faster, regarding two separate occasions: a is a small variable or ...
1
vote
3answers
359 views

Is it bad practice to check object types with an identifying member variable?

Preamble: I am making a simple board game in C++, in which AI characters move around squares on the board. There are different types of squares, each inherited from an abstract class, each with ...
-2
votes
1answer
166 views

PDF to doxygen - how to do it? [closed]

I have a big pdf with the documentation for a project and I need to render this to doxygen (so take each function from the pdf and write it out into doxygen). Any suggestions on how to do this ...
7
votes
1answer
360 views

Creating an effective C++ library website and documentation

Creating a C++ library also means documenting it so that others can use it, and that documentation can vary dramatically in quality. How should a website for a C++ library be structured so that it ...