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

learn more… | top users | synonyms

0
votes
0answers
135 views

Why doesn't grep return TRUE in C++? [migrated]

I'm adapting some of my code from Bash to C++ and I have no idea why this allways returns FALSE. #include <iostream> #include <stdlib.h> int main() { if ( system ("grep -q ...
4
votes
2answers
404 views

Robustness and pointer safety in C++

I'm currently building a server responsible of storing and managing few million records of fairly complex and interconnected data. For reasons beyond my control the work has to be done with C++. I ...
1
vote
2answers
240 views

What is the purpose of creating a member function with the same type as its class?

I'm sure I'll botch some of the specific terminology, but what is the difference between object and object2 in this implementation? Is the only purpose of the first method (prototyping the class's ...
-2
votes
1answer
118 views

What GUI is used in industry for c++ [on hold]

What's the standard GUI designer used in industry for C++? From reading this question, I assume QT? I want to know, if I walked into a C++ software house tomorrow, what would I expect them to be ...
1
vote
2answers
79 views

What is the name of a type that is defined from a template?

To give a complete example, let's say I have a template class that I now use to generate a type definition: template <typename T> struct A {}; using X = // I'm not asking about this ...
-3
votes
0answers
25 views

Execution of char *(*ptr)[]= &arrayOfStrings; [on hold]

Recently I came across this code block char *arrayOfStrings[]={"Monday","Tuesday","Wednesday","Thursday","Friday"}; char *(*ptr)[]= &arrayOfStrings; // LINE A Basically the code was to ...
1
vote
1answer
76 views

Is there a good name for this pointer template?

I'm looking for a proper name of a class template with the following features: It's interface would look something like this, where Foo is a placeholder for the name I'm looking for. ...
-3
votes
0answers
38 views

Reading texts messages into computer for use [closed]

I was referred here after asking this question on Stack Overflow: I want to do a project where I would write a program that takes a file that has read all of my texts messages and then counts the ...
-4
votes
0answers
62 views

Why do i get different results when i enter same input? [closed]

This is a program where i make a linked list and print out the values of the linked list. When i enter a specific sequence of numbers, sometimes the program terminates out of nowhere, and sometimes it ...
-3
votes
0answers
58 views

Calling a function in an operator overload? [migrated]

I have a class A, class A{ private: int num; public: A(int n){ num = n; }; int getNum(){ return num; } A operator+(const A &other){ int newNum = num + ...
0
votes
0answers
3 views

What is the reason behind this Eclipse behavior due to changing an Environment Variable? [migrated]

I have two versions of Eclipse that I use (Indigo for C++ and Helios for Java). I've used both for years without problems. Last week I needed to view Java Bytecode, so in my Environment Variables I ...
-2
votes
0answers
37 views

How to transfer data back and forth between a client and a server on a network [closed]

I have the mandate of transferring data (~3-10mb) back and forth between a client and a server. I ideally need this to work in Windows and Linux. (I would like to stick to c# but can easily ...
-1
votes
2answers
113 views

Does GCC optimize code to remove useless variable read operations? [closed]

I'm using GCC on ununtu 14.04. My program is written in c++ and in a case i need to check the amount of time the program needs to read a large integer array. what is the best way to do this without ...
3
votes
1answer
219 views

Is checking for cin.eof() really necessary?

I have written a simple program that reads character input from the keyboard within a For loop. My professor has taken away 10 points for not checking the input using cin.eof. I don't understand why ...
-3
votes
1answer
65 views

dll of c++ project to be used in c#-project [closed]

I would like to create a dll so that I could use an engine written in c++ for a c#-project. I have tried to google for answers without any perfect results. Just a hint on what to search for would be ...
0
votes
0answers
17 views

Code Coverage Reporting with Visual Studio 2013 Professional for native C++ [migrated]

Using the C++ unit testing framework with Visual Studio 2013 Professional, one can write unit tests and run them from within the IDE, but in order to generate any coverage reports, apparently, one ...
0
votes
0answers
13 views

C++ Matrix multiplication speed custom iterator [migrated]

I am currently writing a linalg library, for educational purposes and personal use. As part of it I implemented a custom matrix class with custom row and column iterators. While providing very nice ...
0
votes
2answers
88 views

C++ Type of a functor returned by bind

I'm currently programming a chess program in C++. The algorithm for searching is alphaBeta, that's why I sort the moves before going through them and evaluating them. My main class is the class ...
2
votes
3answers
157 views

Disallow non-local storage of an object

I need to write a class in C++ that acquires a hardware resource and releases it again when it is destroyed. Basically that can be done in the constructor and destructor of the class. The difficulty ...
2
votes
1answer
144 views

What are the main differences between C++ templates and Java generics? [closed]

I'm a beginning C++ programmer coming from Java. It feels to me that C++ templates and Java generics are actually pretty similar. You use them in pretty much the same occasions and in the same way. ...
0
votes
1answer
163 views

Does C++ abuse the stack? [closed]

Somewhere on the internet, I remember reading someone complain about how C++ puts so much more stress on the stack than C. They didn't go any further to explain what they said, but I understand that's ...
1
vote
1answer
44 views

saving connectivity information in a nodes/edges network

I want to implement the A* algorithm. I have a network with Nodes and Edges, both are classes. Now, I am unsure how to approach the connectivity information. Should a node know which edges depart ...
-1
votes
1answer
62 views

Creating a generic framework for application loading [closed]

I have multiple applications that use a generic framework for creating a graphical user interface. All run with a certain gui.cpp (600 lines) and gui.h (150 lines) containing the int main() function, ...
0
votes
0answers
165 views

Move semantics in C++ - Move-return of local variables

My understanding is that in C++11, when you return a local variable from a function by value, the compiler is allowed to treat that variable as an r-value reference and 'move' it out of the function ...
2
votes
3answers
276 views

What should I do in C++ when implementing a container class: storing objects by value or by reference?

I'm new to C++, coming from Java. In Java, all variables (except for primitives) are essentially pointers. They hold the address of whatever they're 'holding'. So any Java data structure stores it's ...
4
votes
1answer
78 views

Handling interface segregation in C++

I'm designing a "view" handling system for a game. The goal is to be able to have different "views" that can be shown in sequence or stacked on-top of each other. For example, the initial splash ...
2
votes
4answers
296 views

Is this a commonly encountered situation in C++? Is there a pattern to handle it?

I am writing a game in C++, and something I have noticed is that I have many resource files which need to be loaded after a particular point in initialization. For example, OpenGL textures and VAOs ...
0
votes
2answers
92 views

What do you call the line/s of code that declare that a class or function is a template? [closed]

I'm writing some macros which declare template types and I'm a bit stumped for terminology. To illustrate, take the following example: // template class declaration template <typename A, typename ...
-1
votes
2answers
298 views

FizzBuzz on Large Scale

So I was asked to create FizzBuzz at an interview... Easy enough but then they say what if there is a million data points. ie. divisible by 3 divisble by 5 divisble by 6 up until a billion. What is ...
-2
votes
2answers
71 views

Debug symbols change application execution [closed]

I have to set up remote debugging for a multi threaded application running on a embedded device. C++ is the language. I've gotten so far and got the remote debugging working for a simple application, ...
1
vote
1answer
157 views

What kind of game mechanics makes sense to be handled on client side? [closed]

I am aware of that is a difficult question and depends on the game mechanics and game type being applied. So, many answers can be given. For the sake of simplicity, it would be better to consider a ...
3
votes
6answers
339 views

Unit test private method in c++ using a friend class

I know that this is a debated practice, but let's suppose that this is the best option for me. I am wondering about what is the actual technique to do this. The approach that I see is this: 1) Make a ...
0
votes
3answers
278 views

C++ Chess board design and smart pointers [closed]

I wrote a Chess engine in Java and I am porting it over to C++. I am new to C++. The idea: I have a Board object which holds a 2-dimensionnal array of Piece objects. Queen, Rook, Bishop, etc are ...
-3
votes
0answers
26 views

c++ Need help with arithmetic operations [migrated]

I need to make a program that basically reads the 2 numbers that the user inputs and then displays each number by adding, diving, subtracting, and multiplying it all at the same time. This is what i ...
6
votes
4answers
521 views

Does internal state “leak” when it influences externally-visible behavior?

I have a method (in C++) which generates a value based on a parameter and the parameters from previous calls. Calling it more than once with the same parameter may generate different values each time. ...
3
votes
2answers
136 views

Decision making and maintenance

I'm trying to find an elegant way to implement a decision making algorithm that allow easy maintenance because the conditions for the decision making might change often. I'm going to try and be more ...
0
votes
1answer
94 views

Organise C++ classes around SQL database

My question is about how best to organize C++ classes around a database model, and I understand this may appear very elementary. The software I propose to create will do the following. It is intended ...
1
vote
3answers
330 views

C++: Metaprogramming with a compiler API rather than with C++ features

This started out as a SO question but I realized that it is quite unconventional and based on the actual description on the websites, it might be better suited to programmers.se since the question has ...
-1
votes
0answers
60 views

Sharing dynamically allocated arrays between C++ source files [migrated]

I am trying to compile a code with two (more actually, but that is not important) source codes. In one of them I declared a variable size array like this: const int number_of_equidistant = ...
0
votes
3answers
265 views

Good 'real life' example of operator overloading C++ [closed]

What are examples of classes to use operator overloading on in C++? All the examples and tutorials I can find on the net use non-sensical classes/objects (foo/bar, one or two integers..) What are the ...
0
votes
2answers
133 views

How to organise and label methods, intended for debug?

I have a class System, which uses a bunch of other classes, to achieve a complex signal processing. In debugging System, one needs to observe the output signal for patterns. This is not achievable by ...
0
votes
0answers
83 views

c++ understanding size_t behaviour for vector creation [migrated]

this is a folow up to this c++ coding practice class vs. "free" functions question I posted a few day ago. In short, the idea is to create a custom vector class for statistical data ...
1
vote
4answers
393 views

How to work around Java's lack of pointers to pointers when working with linked data structures? [closed]

I've learned from a textbook how to implement binary search trees recursively in Java, and am working on implementing them nonrecursively. I've found a simple and elegant way to implement an insert ...
2
votes
1answer
154 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 : ...
3
votes
4answers
170 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
130 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 ...
0
votes
0answers
42 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 ...
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 ...
-1
votes
1answer
100 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 ...
3
votes
2answers
252 views

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

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 ...