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

learn more… | top users | synonyms

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 ...
-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
68 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
77 views

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

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
240 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 ...
-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? [on hold]

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 ...
1
vote
2answers
331 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 ...
6
votes
4answers
366 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 ...
1
vote
1answer
80 views

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

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 ...
-2
votes
0answers
41 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
3answers
165 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: ...
-3
votes
0answers
54 views

Best way to learn to code? [closed]

I decided I wanted to learn to program so that I could one day make videogames of my own, so I set out to learn c++. I used a website called learncpp.com. First half of the lessons, I have a lot of ...
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 ...
1
vote
1answer
107 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 ...
4
votes
2answers
248 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
2answers
120 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 *); ...
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 ...
0
votes
0answers
86 views

Indexing data in C++. Could a constructor make a new entry if needed, or increment an existing one elsewhere in the larger object containing it? [closed]

I am indexing a file of key pairs, and counting number of appearances. The file goes: A B C A B A D E B F and so forth. Seems like a struct or object being pushed back into a vector is a ...
0
votes
1answer
165 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
108 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
114 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, ...
2
votes
1answer
192 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 ...
1
vote
2answers
214 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 ...
-2
votes
1answer
92 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 ...
0
votes
2answers
168 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 ...
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 ...
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# ...
1
vote
3answers
639 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() { ...
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. ...
-2
votes
0answers
20 views

C++ ofstream adding random data to a file! [migrated]

Here is my code: std::ifstream file2(imageToAdd.c_str(), std::ios::in | std::ios::binary); if(file2){ file2.seekg(0,std::ios::end); length = file2.tellg(); file2.seekg(0,std::ios::beg); ...
1
vote
1answer
112 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 ...
2
votes
1answer
71 views

Best practice for unused inherited virtual functions (implementing superclass methods)

Let's assume I have a hierarchy of several classes each derived from each other using virtual functions. The base class acts as an interface and defines functions, which may not be required by all of ...
-2
votes
1answer
109 views

Uniqueness of for loop [closed]

How does the for loop function is implemented so that it can accept ; as parameter separator rather than , which is trivial in normal functions.
0
votes
2answers
70 views

C++ Data Server and J2ME client communication [closed]

I am working on a robot that has some AI built in. However, the mandated robot controller does not have the power to do the work onboard. This means that I need to use a co-processor. I am writing ...
1
vote
7answers
677 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
2answers
217 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 ...
3
votes
1answer
215 views

Why did GCC switch from Bison to a recursive descent parser for C++ and C?

Was there a language change that required it or some practical reason why Bison was no longer appropriate or optimal? I saw on wikipedia that they switched, referring to the GCC 3.4 and GCC 4.1 ...
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 ...
2
votes
1answer
57 views

Drawing a custom rendered control in Windows - resizing

Some background: in order to learn GUI programming and drawing in Windows I'm starting to create my own GUI toolkit in Windows (so this is a didactic exercise, please don't suggest "use Qt" or "use ...
-5
votes
1answer
73 views

c++ GUI application in linux without toolkit [closed]

We all know , there are number of toolkits available for GUI application in c++ for Linux. But for some reasons I want to create a GUI application without any toolkit.I know this question is ask ...
3
votes
1answer
224 views

Is my class structure good enough?

So I wanted to try out this challenge on reddit which is mostly about how you structure your data the best you can. I decided to challenge my C++ skills. Here's how I planned this. First, there's ...
0
votes
1answer
152 views

Cheerp — C++ for web: advance or regression? [closed]

Recently I've run into Cheerp, a C++ to Javascript compiler, which uses a modified version of clang to generate Javascript code from C++ sources. That makes me wonder: why in the seven kingdoms would ...
4
votes
7answers
979 views

Why do we need to include the .h while everything works when including only the .cpp file?

Why do we need to include both the .h and .cpp files , while we can make it works with making just a .cpp file and then including it . For example, Creating a file.h containing declarations, then ...
23
votes
9answers
2k views

Interface design where functions need to be called in a specific sequence

The task is to configure a piece of hardware within the device, according to some input specification. This should be achieved as follows: 1) Collect the configuration information. This can happen at ...
-2
votes
1answer
161 views

What are steps in making an operating system in C ? [duplicate]

I am trying to make an my own OS. This is for educational purpose only, so that I get to understand the internals as well as get a good idea of low level programming. I have some prior application ...