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

learn more… | top users | synonyms

1
vote
1answer
25 views

How do you achieve the 'BST Property' in a Template Binary Search Tree?

We recently started learning about binary search trees. We created one of our own using integers as our Key/Data. It's easy to achieve the BST property using an int key, but what happens when we ...
101
votes
4answers
10k views

Does a `long` ban make sense?

In today's cross-platform C++ (or C) world we have: Data model | short | int | long | long long | pointers/size_t | Sample operating systems ... LLP64/IL32P64 16 32 32 64 ...
3
votes
2answers
218 views

How does long long syntax work when int int doesn't in C++?

I was wondering if long long specifies a single datatype then why don't things like int int work? I meant obviously that's not a data type but there is a long data type. Essentially what I'm asking ...
3
votes
5answers
429 views

What is the best way to save data of a C++ Program ? Binary vs JSON serialization

We are implementing a CAD program (in C++, Qt) where we have interdependant classes : The smallest brick is the Pattern, it is just a distribution of points. Then we have Layouts which contain ...
6
votes
3answers
3k views

Is relying on implicit argument conversion considered dangerous?

C++ has a feature (I cannot figure out the proper name of it), that automatically calls matching constructors of parameter types if the argument types are not the expected ones. A very basic example ...
2
votes
0answers
103 views

What are the benefits of an input/output component design?

For the company I work at, all of our projects, including a new one started last year, are written in C89. We write for vxWorks (a real time embedded operation system). Our software runs multi-...
28
votes
7answers
3k views

C++ skills higher than C skills? [closed]

I feel that the often seen C/C++ doesn't really describe my skills in my CV. So I'm planning to separate it into advanced C++ knowledge and mediocre C skills. Do you think this is confusing for the ...
8
votes
3answers
4k views

GO instead of C/C++ with cgo [closed]

Is it possible to replace C and C++ with Go + cgo and interface frameworks such as Qt or DirectX with Go? Any potential pitfalls I should be aware of? UPDATE: I see that my question was not precise ...
134
votes
7answers
160k views

When do you use float and when do you use double

Frequently in my programming experience I need to make a decision whether I should use float or double for my real numbers. Sometimes I go for float, sometimes I go for double, but really this feels ...
2
votes
1answer
201 views

How does this C++ assignment work?

I have very limited experience with C++ but I do have plenty of experience with Java and NodeJS. I've decompiled and tried to make sense of a small C++ compiled file and I've come across something ...
0
votes
0answers
87 views

Building a heap in C++

I am learning heaps in C++ and I have a question about heapify function. So in order to build a heap from a random array, you put the elements from the array in a binary tree in order in which they ...
3
votes
4answers
235 views

When should a function take a pointer for a collection to fill vs returning a pointer with a filled collection?

In C++ I frequently see these two signatures used seemingly interchangeably: void fill_array(Array<Type>* array_to_fill); Array<Type>* filled_array(); I imagine there is a subtle ...
1
vote
1answer
80 views

Get or infer template type from inherited member

So I have an assignment from college where I have to apply multiple metaheuristics to different problems. I thought that I should make everything as modular and reusable as possible to reuse ...
0
votes
1answer
120 views

CreateFileMapping() - parameters of size

I want to make a program, which will put some sentence in shared memory so another program will receive this massage. I made that, but I do not understand the 4th and 5th parameters of ...
1
vote
5answers
7k views

How to share memory between applications written in C/C++

I'm going through a program written in C/C++ for control in robotics. Basically, three different programs run at the same time, and they communicate via shared memory. Google-ling around I found ...
4
votes
1answer
138 views

Word ladder efficency problem

I have a problem dealing with word ladders. The problem is: given two words and a dictionary file, find the shortest word ladder between the two words. So if given the words cat and pot: cat -> ...
1
vote
3answers
333 views

Do I have to fork a server program as an “C” child process in order for correct interprocess communication to take place?

I would like to implement interprocess communication between an Ubuntu Linux 15.10 mono 4.1.2 C# recorder client and Ubuntu Linux 15.10 mono 4.1.2 C# video server using a C++ mutex class and C++ ...
0
votes
2answers
129 views

Naming when having to inherit classes [closed]

I am always a huge fan of standards and think I finally decided on one of the many C++ naming standards. However, it almost seems moot because working with a couple of libraries where the standard use ...
2
votes
0answers
61 views

Default move assignment and destruction order of members versus the rule-of-zero

Members must frequently be destroyed in the correct order. As member creation is in forward order and destruction is in reverse order this will usually work fine. However, when assignment operators ...
2
votes
2answers
332 views

Could someone write an opensource version of the Windows API?

I am wondering if it is both possible and how one would write an opensource version of the Windows API. What I mean by this is, say you #include <Windows.h> in your C++ application. Then you ...
2
votes
1answer
89 views

What is MISRA 8-0-1 rule on init-declarator-list and member-declarator-list about?

I am reading company's coding guidelines, and I encountered the MISRA 8-0-1 rule, which states: An init-declarator-list or a member-declarator-list shall consist of a single init-declarator or ...
4
votes
2answers
129 views

Design question about hiding implementation from users of a dynamic library

I'm building a DLL and in my public headers I have this: (definitions are in .cpp but for clarity I show them in .hpp here) ObjectTag.hpp: class API_DLL ObjectTag { public: ObjectTag() : mUUID(...
19
votes
8answers
847 views

Dealing with coworkers when developing, need advice [closed]

I developed our current project architecture and started developing it on my own (reaching something like, revision 40). We're developing a simple subway routing framework and my design seemed to be ...
1
vote
1answer
149 views

Does having so many macros (#define) increase compilation time due to prolonged pre-processing?

In a very simplistic way, I understand: "Compilation" = "Pre-processing" + "Parsing" + "Linking" + "Executable" All the macros and other such pre-processing directives are taken care at the "Pre-...
21
votes
5answers
14k 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.) ...
1
vote
2answers
179 views

Why doesn't the compiler complain when I try to access a non-existent array value?

My C++ book says that if I have int anArray[25]; and I try to evaluate anArray[25] = 0; the program will simply overwrite whatever value is stored in the next memory address past the end of the ...
2
votes
3answers
153 views

Adding a function to class member

I'm not sure of the proper terminology here so I'm having trouble finding the answer to my question but here is what I want to achieve. say I have class ABC { public: int number; }; and I ...
0
votes
0answers
75 views

Arbitrarily sized (and signedness) integer arithmetic in C++ - How can it be done generically at runtime?

How can I efficiently handle integers of unknown size and signedness in various arithmetical operations in C++? (for a virtual machine). I am storing the program for the virtual machine in a string ...
4
votes
1answer
384 views

Why double colon instead of dot?

It is rumoured that early C++ implementations have had dot operator for namespace access. There is an opinion that the dot is more convenient that the modern double colon operator. What was the ...
6
votes
2answers
373 views

Why is threading platform-dependent?

I am reading book "Foundations of Qt Development", Chapter 12, and I read that threading is platform-dependent, can someone explain, why? I know how to use threads but that what they said is not so ...
3
votes
2answers
141 views

How to write unit tests for network client?

I need to write simple http client. It could be great to have unit tests for my class. But I don't know how to write proper and testable class. For example, I have a client like this: class ...
-2
votes
1answer
83 views

Static Polymorphism explained

Here is a code I have got from here: class Deletor { public: virtual ~Deletor() {} }; template<typename T> class Base : public Deletor { public: int Run() { return ...
2
votes
3answers
178 views

When to mark a function as virtual?

I'm trying to understand the idiomatic way to code. I'm using gmock to unit test the components I write. Gmock requires methods to be virtual to be able to mock but the class I'm trying to mock has a ...
3
votes
2answers
240 views

How to stay DRY with return values

I have a bunch of repetitive C++ code that looks like this: // Compute finalOutput if possible. Return true if successful, false otherwise // finalOutput only holds a valid value if true is returned. ...
4
votes
3answers
129 views

How should I write an interface that takes a list of items?

I'm writing a library function that takes a list (or "bunch") of items (let's say Student) and does something with them. What's the best way to write the function signature in the interface? std::...
86
votes
13answers
8k views

Way in over my head! (Dealing with better programmers) [closed]

I've just been hired as a member of a group that is developing in C++. For the last 11 years, I'd been coding on and off at my last job (some C, some Fortran, some C++). The coding I'd done was ...
18
votes
5answers
7k views

If a variable has getter and setter, should it be public?

If I have a class with a variable that is private and the class have getter and setter for that variable. Why don't make that variable public? The only case I think you have to use getters and ...
5
votes
3answers
271 views

How aggressively to change in-house smart pointer to unique_ptr?

I work on a large software product which, being over 20 years old, has a number of constructs which have been superseded by language updates. One of these is a home-rolled smart pointer template ...
1
vote
3answers
419 views

Which languages allow to mix its source code with C++ source code?

I have read that there are languages other than C++ that can also compile standard C++ source code too (Objective C++ can do this). Which other languages for Windows and Mac OS are there, that support ...
2
votes
3answers
3k views

Can I make a good career with VC++ programming? [closed]

I'm addicted to VC++ since 2008, and I begin to work for my current company from 2011 when I graduated in Mathematics. Now I still love VC++, it is a wonderful programming language. I'm a little ...
39
votes
3answers
135k views

Android development using C and C++ [closed]

I am a C, C++ developer. I am interested in mobile development. I want to know how can I develop Android apps using C and C++, I have read that they are providing a kit for C, C++ developers but it ...
1
vote
2answers
101 views

Catching exceptions from child process

I am looking for any info. (I know some C++ with win32 and C#) The Idea: The idea is to help a program with missing files load. In the end I wanted to see if I could have my program launch a simple ...
-2
votes
3answers
180 views

Is it possible to have private or protected objects in Java? Or are all objects considered public?

Is it possible to have private objects? For example, when you instantiate an object (classType object1 = new classType()), can that be private or protected or is it always public?
0
votes
1answer
144 views

Find if certain files have been added or removed in large directory structure

I have a larger directory structure (dir + sub directories) with files. It contains files of certain types. For one particular type (let's say with appendix .foo) I need to figure out if files have ...
0
votes
5answers
253 views

Is there a better way to debug while avoiding getters/setters?

I'm thinking about how to debug better without using Getters/Setters. If it helps, I program using xcode. Many answers in Stack Exchange have argued against Getters/Setters for lack of encapsulation (...
8
votes
5answers
548 views

Is it correct to say that a variable is an instance of a data type?

(that can change its value over the course of the program) Or is 'instance of something' strictly related to classes and objects? If so, how would you define the concept of 'variable' when it comes ...
2
votes
2answers
447 views

Should we “balance” the amount of codes between headers and cpp?

As far as I know, cpp usually contains far more codes than headers, mainly because they contain implementation details of functions instead of just one line of function definition. Here comes to my ...
13
votes
1answer
307 views

Should I add the source of libraries instead of linking to them?

I'm relatively new to C++, so I'm not sure how I should best handle small dependencies (e.g., a scripting language, or a JSON/YAML/XML Parser). Should I create separate projects and link them as ...
7
votes
1answer
91 views

Visitor Pattern, replacing objects

I have a program that translates a DSL to C++, which uses a Visitor pattern on the intermediate representation. I quite often need to replace the currently processed node with one of a different type ...
1
vote
0answers
82 views

How to structure enum data to achieve the desired effect

I'm making a framework for building simple html websites for an embedded system and I want to make it bulletproof in a way that a user can't make mistakes in building the html document. As I've ...