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

learn more… | top users | synonyms

1
vote
4answers
256 views

What is “using namespace” pollution?

I was looking at the google coding guide [here] and they do not recommend that one use the using namespace ornamespace:function` - if I did not misinterpret it. Does this apply to std as well? ...
3
votes
2answers
211 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 ...
0
votes
1answer
54 views

Rewriting code under BSD license

I am currently studding OpengGL with OpenGL Supebible 5th edition. I've found interested for me some C++ code that is distributed with the book (see also on google code). That code is under New BSD ...
12
votes
4answers
773 views

What is the pattern for a safe interface in C++

Note: the following is C++03 code, but we expect a move to C++11 in the next two years, so we must keep that in mind. I'm writing a guideline (for newbies, among others) about how to write an ...
-1
votes
0answers
71 views

What kind of programs is C++ suitable for? [on hold]

I have learnt C++ is mostly used for system programming and understand that is because it allows low level programming like bit manipulation etc. Is there any other specific reasonsI am missing? ...
0
votes
2answers
158 views

Application qos involving priority and bandwidth

Our manager wants us to do applicaiton qos which is quite different from the well-known system qos. We have many services of three types, they have priorites, the manager wants to suspend low priority ...
-4
votes
1answer
59 views

TopCoder Algorithm - Detecting Squares [on hold]

I'am solving TopCoder Algorithms, I need help. What kind of algorithms will be useful in this situation? My input is a list of coordinates x and y specified by length plus coordinate pairs: 9 5 3 1 ...
1
vote
5answers
567 views

How do I deal with global variables in existing legacy code (or, what's better, global hell or pattern hell)?

So... We have this fairly complex project (~10k LOC, but there's duplicated code so it's hard to tell) with hundreds of global variables. The project has more dependencies on other projects, and many ...
0
votes
3answers
417 views

Design for multiple type return

I am working in C++ and I have this problem. class Container { Container(int which_type_to_use_a_b_or_c); A & getData(A & prototype); B & getData(B & prototype); C & ...
139
votes
14answers
65k views

When to use C over C++, and C++ over C?

I've been introduced to Computer Science for a little over a year now, and from my experience it seems that C and C++ are both considered to be "ultrafast" languages, whereas others such as Python and ...
0
votes
3answers
219 views

Understanding object-oriented programming: why is it important? [duplicate]

Just started learning about classes in C++ and I'm have trouble understanding why object orientated programming (OOP) is useful. I understand the syntax, how to use them etc. But I'm still confused ...
0
votes
0answers
5 views

c++. Smart pointer for a member object of a class whose instance itself is owned by a smart pointer. Necessary? [migrated]

alert--- c++ noob coming from C# here --- class Foo { public: int fooInt; }; class Bar { Foo fooInBar; }; int _tmain(int argc, _TCHAR* argv[]) { std::unique_ptr<Bar> myBar = ...
0
votes
4answers
375 views

How does assembly relate to machine/binary code

How does assembly relate to machine/binary code. For example here is how to print to the screen in mikeOS(a small pure assembly OS), mikeOS it uses NASM to assemble. BITS 16 ORG 32768 ...
0
votes
7answers
3k views

Performance analysis of C++ programs [closed]

How can I measure the performance of my C++ programs using C++? Specific metrics I want to measure are: Memory used (space) Duration taken (time)
0
votes
1answer
82 views

Estimed number of tries

Problem: The Oscar Committee wants to decide which person should get the best actor award among the given N actors.For that they decided to use a random function random_bit() which returns either 0 ...
0
votes
1answer
64 views

Splitting and hiding headers in a static library

I am writing a static library for C/C++ (personal project). As my headers became rather large, I thought that splitting my headers would be a good idea. Right now a header looks like this: ...
0
votes
0answers
10 views

Sempahores and Mutex Lock [migrated]

two scenarios, what is the difference. I cannot understand which to use. It seems that they basically do the same thing. pthread_lock(&mutex) critical section pthread_unlock(&mutex) vs ...
3
votes
2answers
116 views

How to manage memory in C interface for C++ implementation considering c++11?

I have a library implemented in C++ which has a C interface. This C interface is, for all intents and purposes, the only way to use this library. C++11 seems to discourage the use of raw pointers but ...
-1
votes
0answers
27 views

How do I save and load a std::string with object serialization in C++? [migrated]

I had something simple like this POD structure... struct Actor { string name; int hp; }; Later on, for simplicity sake here, I saved the structure to file using... ...
0
votes
1answer
89 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 ...
0
votes
1answer
44 views

How to make C++ template stack work with basic data types and compound variables?

Templates are nice for similar algorithms of different data types. Say I make a template stack of a basic data type... Stack<int> stck(10); stck.Push(5); I'd pop it... int x = stck.Pop(); ...
14
votes
4answers
792 views

Which one of these answers regarding functions is incorrect?

So while I've been doing some lengthy compiles I decided to take the C++ general test on ODesk and came across this question. If I'm not mistaken, given the wording (or lack thereof) all of these ...
-5
votes
0answers
22 views

Closing MessageDialog windows with a timeout [closed]

GTK - GTKMM In gtkmm messagedialog, How do I set a timeout handler to activate the OK button in the dialog window. I have a timer which counts down in seconds but when it reaches 0 it just hangs. The ...
3
votes
1answer
71 views

In c++, difference between linking a class object and just including it.

this is my first time here. I'm a physics grad student and I've recently found a research group to work with. We study statistical mechanics using computer models, so there is a significant ...
0
votes
1answer
179 views

Does it make sense to choose UTF-32, based on concern that some basic rule will be broken for UTF-8?

I'm working on an cross platform C++ project, which doesn't consider unicode, and need change to support unicode. There is following two choices, and I need to decide which one to choose. Using ...
2
votes
2answers
163 views

Testing abstract class' behavior

I'm currently refactoring an existing design, which was created without TDD. There is a class hierarchy with one abstract base class and two subclasses. In the original design, these classes were ...
-1
votes
0answers
58 views

Linear Algebra Api for c++ using external memory [closed]

I need to perform Linear Algebra operations on Large size vectors and matrices which might or might not be sparse. Operations better include LU Factorization for matrices in addition to the basic ...
0
votes
2answers
204 views

Can this argument be enough?

We have two C++ classes named Important and Small The class Small use a few methods and attributes from the class Important, but not all. Since our application is performance critical, instead of ...
3
votes
2answers
204 views

How to find number of points with same minimal distances on matrix

I'm trying to find the number of points in a matrix with the same minimal distances. Start with a MxN matrix, where M and N < 50000. There is given a set of fixed points, with their respective ...
0
votes
1answer
332 views

Good practice using signals and event driven system

I am using signals (specifically Boost signals2) to create an event driven protocol API and model. Most elements have their own signals, and there are usually multiple of each element. Consider a ...
78
votes
15answers
7k views

Why did memory-managed languages like Java, Javascript, and C# retain the `new` keyword?

The new keyword in languages like Java, Javascript, and C# creates a new instance of a class. This syntax seems to have been inherited from C++, where new is used specifically to allocate a new ...
0
votes
0answers
22 views

How to declare two dimensional array accessible from other functions? [migrated]

I have a quick Question: If I want to have a two dimensional array accessible from other functions, should I define it as a static ? and If so, How can I initialize it using other members. Here is ...
0
votes
1answer
562 views

Is this proper OO design for C++?

I recently took a software processes course and this is my first time attempting OO design on my own. I am trying to follow OO design principles and C++ conventions. I attempted and gave up on MVC for ...
1
vote
4answers
238 views

Wrapper around C++ STL

Where I work we have our own system library, which pretty much is only wrappers around the STL, such as: template <typename T> class HVector { protected: std::vector<T> data; public: ...
-1
votes
0answers
11 views

Finding in std::list [migrated]

Tell me please how to do that the best using STL. I have class that has a member std::list. It's private member. I have only const_iterator to begin and end. I'd like to check if list has some ...
1
vote
1answer
133 views

How to break these long C++ lines in a neat way? [closed]

I'm on my first bigger C++ project and find that I have some really long lines. My goal is to break them to 79 columns, but I do not really know how to do this in a neat way. Are there some guidelines ...
-1
votes
2answers
66 views

What is a simple explanation for the reinterpret_cast expression? [closed]

I see that it is a compiler directive which instructs the compiler, but what does that mean?
0
votes
1answer
98 views

Do C++ library developers only write C compatible interfaces as an afterthought? [closed]

I have developed the distinct impression that although C++ libraries are often developed for other slower languages to link with when performance is needed, some feature known as name mangling and ...
5
votes
4answers
1k views

Learning C for C++ programmers [closed]

That's right, I learned to program in C++, and of course know the common set of features of both languages, so I can program in C. But I'd really like to read tutorials or books that teach you C, and ...
-1
votes
4answers
2k views

Can I change operator precedence and associativity in C++?

As the title says, I find it useful to be able to overload operators. Is it possible to also change the way the operators are parsed by specifying the precedence and associativity of overridden ...
1
vote
2answers
117 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 ...
-2
votes
0answers
30 views

Is there a way to initialize a container with one line? [migrated]

I am looking for vanilla C++89 solution (no boost, or qt, etc.) Is there a way to do something like this : // valid in c++ 11 std::vector<Foo> vFoo {Foo1, Foo2, Foo3, Foo4} ; or something ...
0
votes
1answer
211 views

What data structure is suitable for implementing dynamic huffman encoding and decoding on a piece of text?

Some pseudo code or resources will be appreciated.I was thinking if implementing it in form of a BST stored in an array. However,not all operations can be performed easily using this approach. I am ...
-4
votes
0answers
24 views

I have a class that is derived from a QList object. I have used for loops, I keep getting the error that list is not declared in the scope [migrated]

I have a class that is derived from a QList object. I have used for loops, I keep getting the error that list is not declared in the scope #include "AssetList.h" #include "Asset.h" ...
-2
votes
0answers
94 views

Is there any other way to run .exe from Java? [migrated]

The main problem is that I cannot run my c++ logic by running it through Java; am I creating a subprocess properly? Thank you all; --- UPDATE! --- So I have written these to test the ability to open ...
1
vote
0answers
60 views

Guideline for managed (C#) and native code (C++) hybrid development [closed]

Is there any guideline for a mixed managed and unmanaged system architecture? Given the same amount of time I find managed code to give better performance. The default to pass by (constant) ...
-2
votes
1answer
116 views

Use cases for C++ in native mobile applications (iOS, Android, Windows Phone) [closed]

I am working on an project which permits to order, select recipients and pay products from mobile applications on Android, iOS and Windows Phone 8. I wish to avoid rewriting code between each ...
1
vote
3answers
325 views

Should I pass array or pointer?

I am writing a C++ library (but prefer C style interface functions) and one of the function returns array of floats. I am not sure if I should pass pointer or fixed array to get this data? // in the ...
0
votes
2answers
105 views

Characterization in Testing: Unit test or Functional test [duplicate]

So I'm trying to push for more automated testing in my company, which focus a lot on prototype and proof of concept systems. We currently use Google Test for unit testing. This tests specific test ...
2
votes
2answers
152 views

Injecting dependencies (DI) in c++ applications

I am playing with dependency injection, but i am not sure I am doing it right. Especially, I am not sure what should be the correct way to build classes with injected dependencies. Say I have a class ...