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

learn more… | top users | synonyms

3
votes
4answers
97 views

Storing a pointer to an argument passed by (non-const) reference

When designing an interface for passing objects which are meant to be stored for later use and which should not be 'null', I am always a bit uncertain if the argument should be passed by reference or ...
0
votes
2answers
109 views

Can I create a type, typedef or using statement that results in a different type if instantiated a second time or more?

Suppose I have a class that evaluates some computationally intensive function: class Value { private: int eval() { mCached = ExpensiveOperation(); return mCached; } static int ...
1
vote
1answer
103 views

How do multiple levels of inheritance affect virtual function call overhead in C++?

I am considering using a class hierarchy with more than a single level of inheritance, where virtual member functions form a "chain", for example: struct Base { virtual void foo(); }; struct D1 : ...
0
votes
0answers
30 views

API for accessing CTS and DSR signals of serial port

I'm trying to improve another abstraction of the serial port. The project involved often needs to check one of the single control signals CTS and DSR. This is currently done by a call to ...
22
votes
10answers
7k views

Why are pointers not recommended when coding with C++

I read from somewhere that when using C++ it is recommended not to use pointers. Why is pointers such a bad idea when you are using C++. For C programmers that are used to using pointers, what is the ...
8
votes
7answers
280 views

How does a variable introduce state?

I was reading the "C++ Coding Standards" and this line was there: Variables introduce state, and you should have to deal with as little state as possible, with lifetimes as short as possible. ...
0
votes
0answers
4 views

error LNK2019: unresolved external symbol? [migrated]

Firstly, I am beginner in c++ and Visual C++ (but not OOP). I am now trying to import Excel data to my data structure. What I have done is creating the structure(as class) in dataStructures.cpp along ...
6
votes
4answers
415 views

Undefined behavior, in principle

Whether in C or C++, I think that this illegal program, whose behavior according to the C or C++ standard is undefined, is interesting: #include <stdio.h> int foo() { int a; const int ...
3
votes
2answers
242 views

Does ODBC require any run-time software beyond an .exe file to run against MySQL and ORACLE SQL? [on hold]

I'm writing a software [under Windows] in C++ which later needs to be able to connect to both MySQL and ORACLE SQL. Now the software needs to be as simple for the user as possible. Now I'm ...
-3
votes
0answers
34 views

Output of a program [migrated]

{ int a; a=4; cout<<a++<<++a; } The output of the above C++ program is 56 but why it is not 46 As a++ first print the value then increment a.
-6
votes
0answers
73 views

Finding the minimum and maximum value in C++ [on hold]

Well, I am a newbie at programming and I was trying to write the code in C++ to find the minimum and maximum values from a set of integers. Now this program takes integer numbers as inputs from the ...
-1
votes
1answer
80 views

What are guidelines for a Win/Mac/Linux C++ source tree? [closed]

I'm learning C++ (C++11), specifically for cross platform game development using SDL. on Windows, I use Visual Studio 2012 (Considering buying '14' once it's out), on Mac OS X and iOS I'll be using ...
0
votes
1answer
258 views

Interface questions for using Command Pattern and Dependency Injection together

I have many projects that have essentially the same high level requirement: test all hardware on a device. Each device can have a different communication protocol, requires different test equipment to ...
1
vote
2answers
347 views

c++ coding practice class vs. “free” functions

I am currently writing my first bigger project in c++. Its basic linear algebra. I am aware that boost libraries and others exist, but for various reasons I need to write my own. Purpose of the ...
-2
votes
0answers
139 views

How to call a function with argc & argv? [migrated]

I'm currently trying to create a GUI for an existing command line program using QT, as a learning exercise. The original code was written in c, and I have included the c wrapper for the c++ bit. I ...
-2
votes
0answers
43 views

Where to learn C++ object linking? [closed]

I'd like to use an open-source library in my application (we'll call it library X). There is a patch that I've applied to it (not my patch) that adds some pre-processor checks for a certain macro ...
26
votes
5answers
8k views

Why is there no 'finally' construct in C++?

Exception handling in C++ is limited to try/throw/catch. Unlike Object Pascal, Java, C# and Python, even in C++ 11, the finally construct has not been implemented. I have seen an awful lot of C++ ...
1
vote
1answer
80 views

Standardization and official guidelines for C++ template parameter naming [closed]

What are some explicit and official guidelines or standards for template parameter naming in C++? I've done something like this in the past: template<typename TContainer, typename TKey> void ...
0
votes
0answers
49 views

how to do vector ops on a “vector <string> item” C++ [migrated]

I am trying to work on an array of strings (char **) where I am trying to use the C++ paradigm of "vector device_names". After parsing an input string for matching pos/neg entries, I want to sort ...
1
vote
3answers
166 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: ...
-2
votes
0answers
43 views

Segmentation fault with a c++ file handling program [closed]

I am learning file handling c++. This program read words from a file and inserts them in a vector alphabetically as they are entered. When I am executing this program, I am getting segmentation ...
1
vote
0answers
53 views

Function pointers to object instance returned by function pointer [migrated]

Im new to c++. I want to make a std::map with strings of get-method names mapped their respective get-method. These are to be looped over and present the value obtained by the get-methodtogether with ...
4
votes
2answers
253 views

dealing with a very large state machine in a class

I am currently implementing a class for a network protocol. The protocol uses a quite complex and extensive finite state machine. A pair of an event plus a state is mapped to a function, which does ...
1
vote
1answer
111 views

C++ : Association, Aggregation and Composition [on hold]

I'm beginning to study OOAD and I'm having difficulty finding a C++ code example that'd illustrate how Association, Aggregation and Composition are implemented programmatically. (There are several ...
1
vote
2answers
121 views

How to abide the “allocate in caller” rule when the size is computed in the callee?

Let's say we have an opaque type handle_t that is managed through a simple interface with functions such as: handle_t *handle_init(void); int handle_do(handle_t *); void handle_free(handle_t *); ...
81
votes
11answers
21k views

What backs up the claim that C++ can be faster than a JVM or CLR with JIT? [closed]

A reoccurring theme on SE I've noticed in many questions is the ongoing argument that C++ is faster and/or more efficient than higher level languages like Java. The counter-argument is that modern JVM ...
1
vote
2answers
215 views

How to avoid redundant code in designing inheritance in C++

Say I have a Base class called Car and it has 3 derived classes say Ford, Honda and Audi. The issue is, all three derived classes have exactly same code but minor difference in calling member ...
17
votes
6answers
5k views

Dependency injection ; good practices to reduce boilerplate code

I have a simple question, and I'm not even sure it has an answer but let's try. I'm coding in C++, and using dependancy injection to avoid global state. This works quite well, and I don't run in ...
0
votes
0answers
13 views

On linux, how to get “incompatible” i386 f77 libraries to work with current Fortran compilers, like gfortran? [migrated]

I would like to run the elf32-i386 library libkernlib.a with a Fortran 77 program on my latest Ubuntu linux machine. From what I've read, gfortran is backwards compatible with Fortran 77, but I'm ...
0
votes
0answers
20 views

Port forwarding and C++ Winsock Client-Server applications [migrated]

As the title says, I'm creating a TCP client and a server program in C++. My question is, when running the client and server on two separate machines that go through a different firewalled router over ...
9
votes
4answers
1k views

What is use of universal character names in identifiers in C++

The C++ standard (I noticed it in the new one, but it did already exist in C++03) specifies universal character names, written as \uNNNN and \UNNNNNNNN and representing the characters with unicode ...
0
votes
1answer
167 views

Polymorphic engines in C and/or C++ [closed]

I stumbled across polymorphic engines and I don't know anything about them. However, I am curious about how they are written. Every example that I've looked up writes them in assembly, my assembly is ...
-3
votes
2answers
105 views

Why friend in C++ should be in the header file? [closed]

Friend function/class, FriendOfX for some arbitrary class X is an implementation detail of class X. Why in C++ we have to declare them in the header file? Are there any compelling reasons to make this ...
-7
votes
3answers
110 views

What's the list of how to precisely talk about problems in C++ code within the spec? [closed]

The C++ specification leaves a lot of leeway such that when you write bad code, compiler authors are not responsible for defining a specific mode of failure. We know of course that is Undefined ...
-3
votes
1answer
115 views

Is this a good use of a base class? [closed]

I am developing some HW drivers, which access registers. I have a few classes, for example. ClassRegisterBlock1, ClassRegisterBlock2. In each of these classes, they define the bits to manipulate, ...
0
votes
0answers
71 views

initializer_list combined with other parameters [migrated]

Suppose I have a class which takes a parameter of type T and a collection of parameters of type U in the constructor. The following solution works: struct Q { Q(T t, ...
3
votes
5answers
1k views

Boundary conditions for testing

Ok so in a programming test I was given the following question. Question 1 (1 mark) Spot the potential bug in this section of code: void Class::Update( float dt ) { totalTime += dt; ...
2
votes
1answer
196 views

Any OOP design pattern that is somewhat representative of all of the SOLID OOP design principles at play?

I'm trying to teach an object oriented design principles course (on SOLID) at a training institute. I also want to teach the students a few OOP design patterns such as factory, singleton and one ...
4
votes
3answers
3k views

Is it important to obfuscate C++ application code?

In the Java world, it seems to sometimes be a problem, but, what about C++? Are there different solutions? I was thinking about the fact that someone can replace the C++ library of a specific OS ...
1
vote
7answers
679 views

Where is the 'this' variable stored?

Let's take this simple c++ program as an example: #include <vector> class A { void fun() { a = this + 1; } A* a; }; main() { std::vector<A> vec; vec.resize(100); } Forgetting ...
1
vote
3answers
222 views

How to manage focus for a small set of simple widgets

I'm developing a set of simple widgets for a small (128x128) display. For example I'd like to have a main screen with an overlay menu which I can use to toggle visibilty of main screen elements. Each ...
0
votes
2answers
173 views

Mobile App Development-Architecture/Platform: Main performance concern: device/UI responsiveness [closed]

I am currently investigating different alternatives for building a mobile instant messaging application for iOS and Android, using an XMPP server (probably ejabberd) as the back-end. Main requirements ...
-2
votes
1answer
94 views

OOP and Data Structures in C++? [closed]

Is it a must to study Object Oriented Programming before going into Data Structures in the C++ language or can I begin with lists, stacks ,queues,sorting ......etc and does Object Oriented Programming ...
3
votes
2answers
163 views

Are there alternatives to using an optional type in a multithreaded environment?

I'm making an MPMC queue in C++, and I would like to find out what the best interface for a try_dequeue method would be (I'm not concerned about its implementation). I'd like to provide a method which ...
1
vote
3answers
640 views

Is this a good design in C++?

Is it a good idea to replace getters and setters with a single function returning a reference? For example, instead of this, class Person { std::string name; public: std::string GetName() { ...
1
vote
2answers
231 views

2D linked list vs. multidimensional array/vector

I hope that programmers is the correct stack exchange for this, as it is quite a concept based question. I'm working on a data structure in C++ that is a represents data in 3D space. The x-y plane is ...
1
vote
1answer
116 views

Multithreaded Pre/Post Functions

I'm programming an application for an embedded device. We are using an RTOS that supports multi threading. The device is supposed to mimic an older project that was programmed in plain C (without ...
3
votes
2answers
150 views

On concatenating adjacent string literals

C and C++ compiles adjacent string literals as a single string literal. For example this: "Some text..." "and more text" is equivalent to: "Some text...and more text" In other languages like C# ...
2
votes
1answer
70 views

class hierarchy with structurally different subclasses

I want to implement a protocol layer which sits on top of the TCP/IP stack. There is a limited set of PDUs that can be sent and for each PDU there is a class which represents it in a structured form. ...
1
vote
1answer
115 views

How should a GUI application written in WinAPI be structured and organized? [closed]

I've done an extensive amount of GUI programming in Winforms and WPF using C#, and a tiny bit in C++ using MFC. I'm building a personal project using WinAPI mainly to gain a deeper knowledge in ...