Tag Info

New answers tagged

0

What should be at the top of inheritance tree of Decorator design pattern? How to discriminate: non-abstract class - Only if it makes sense in your code to instantiate it in client code (also see: liskov substitution) abstract class or interface - most common case; This is when it doesn't make sense for client code to instantiate it; To distinguish ...


0

It depends entirely on what you want. These variations exist for your convenience, not because one way is a better way than another. Personally I'm partial to the non-abstract class, because it requires the fewest number of classes, which in my opinion is always a plus. However, you may find yourself in the situation in which there is an AbstractText ...


0

I think it's perfectly OK for a "feature" to need an "application", but the use of globals is nauseating. Constructor dependency injection can solve this problem, and allow a gradual refactoring of code. (I'm not a C++ developer, so any corrections/clarifications are welcome) First, the Application class: class Application { public: void ...


1

What you are after is not very specific for OOP, and has absolutely nothing to do with inheritance. You are after proper modularization. Each of your features should be a component, that means either a single class, or a group of classes, with a well defined interface, and not directly dependent on the Application object. In the current situation each ...


2

How to visualise this data model where every node is pointing to a list? Is their a standard approach to visualise any data model, with the given data members and methods of a class? It is a doubly-linked list. The fact that each node "knows" the list is more of an implementation detail than it is a matter of the data model architecture. Possible ...


0

After looking at the XGList code for a while, I think it's meant to be a doubly-linked list in which each node has a pointer to the list itself (i.e. the object with the head pointer, tail pointer and count of total nodes). Presumably the purpose of this is to allow the list to keep track of its own node count, so retrieving the list's size is a constant ...


1

I believe what you're directly asking for is covered by the combination of these StackOverflow questions: http://stackoverflow.com/questions/1528298/get-path-of-executable http://stackoverflow.com/questions/675039/how-can-i-create-directory-tree-in-c-linux The unfortunate reality is that these tasks cannot currently be done in a portable fashion as there ...


1

It is operating system specific. On Linux with X11, you could simply use the fact that DISPLAY is an unset environment variable outside of graphical desktop interfaces (or test for the success of XOpenDisplay); You might also use isatty(3) on STDIN_FILENO(which is 0) to test if stdin is a terminal (but you could also open /dev/tty and see if it fails, cf ...


0

A few additional points worthy of mention: The compiler can process some kinds of constant expressions which the preprocessor cannot. For example, the preprocessor will generally have no way of evaluating sizeof() on non-primitive types. This may force the use of if() in some cases. The compiler will ignore most syntax issues in code which is skipped in ...


2

I do not have enough reputation to comment but everything that was said in the other answers is very relevant. One important thing partially mentioned by ddyer is that wrapping malloc/free has benefits. He mentions a few but I would like to add a very important debugging tool to that: you can log every malloc/free into an external file along with a few lines ...


2

Both of your designs have the problem that they put the burden of keeping track of the validity of the favoriteColor attribute on the user of the class. Your second design (with the getHasFavoriteColor) has the additional problem that it duplicates the information if there is a valid value for favoriteColor in a way that makes it very easy to create ...


0

I don't know C++ but I hope my idea helps you to resolve your problem. Create your model class based on your XSD file. class Person { private string name; private string favoritColor; public Person (XmlElement person) { // parse the XML element and assign the values to appropriate element // if the element does not exist, don't assign ...


14

Enums do not create brittle interfaces. Misuse of enums does. What are enums for? Enums are designed to be used as sets of meaningfully named constants. They are to be used when: You know that no values will be removed. (And) You know it is highly unlikely that a new value will be needed. (Or) You accept that a new value will be needed, but rarely enough ...


4

Enums are a great improvement over magic identification numbers for closed sets of values that do not have a lot of functionality associated with them. Usually you don't care about what number is actually associated with the enum; in this case it is easy to extend by adding new entries at the end, no brittleness should result. The problem is when you have ...


1

If you are careful in how you use them, I'd not consider enums harmful. But there are a few things to consider if you want to use them in some library code, as opposed to a single application. Never remove or reorder values. If you at some point have an enum value in your list, that value should be associated with that name for all eternity. If you want ...


15

Any change to the ColorChoice enum affects all IWindowColor subclasses. No it doesn't. There are two cases: implementers will either store, return and forward enum values, never operating on them, in which case they are unaffected by changes in the enum, or operate on individual enum values, in which case any change in the enum must of course, ...


21

When used properly, enums are far more readable and robust than the "magic numbers" they replace. I don't normally see them making code more brittle. For instance: setColor() doesn't have to waste time checking if value is a valid color value or not. The compiler has already done that. You can write setColor(Color::Red) instead of setColor(0). I believe ...


1

After experimenting for a while I have a solution. I've split the network of machines into many EnergyNet objects, which represents something like a cluster of wires. Each EnergyNet represents a system of energy suppliers, consumers, and storagers, which are a combination of both. Every update tick, the energy net measures the amount of energy produces and ...


1

(Disclaimer: I only have experience in parallelizing computational workloads. I do not have experience in async I/O. The opinions herein are merely based on reading online articles, blogs and Q&A websites.) Applying concurrency to a C++ project is more or less a rigorous exercise in software engineering risk management. You have to choose strategies ...


0

What I am doing is to keep most of the strings in one resources.h file where i am formatting it as follows #include <string> #include <vector> struct Class1_Res { const std::wstring string1 = std::wstring(L"string 1"); ---------------- } struct Class2_Res { const std::wstring string1 = std::wstring(L"string 1"); ...


1

On Linux, if compiling code with GCC, the static data's constructor is run at dlopen(3) time. See also the visibility attribute and the GCC specific __attribute__((constructor)) for functions. However, you should define a plugin convention: which names (for extern "C" C++ functions inside plugins) are used, with which signatures, in what order, etc. For ...


0

Are they semantic kind of way related? No. Their development followed a somewhat similar path in creating the syntax (for example, both support exceptions and they have many keywords in common, with similar semantics). I am learning C++ and I want to start java too. Can I get confused when learning the two languages? You can definitely get ...


2

The question is, how do I do this in C++? You will not be able to map the Perl initialization in C++ without making it explicit. Components for a plugin system in C++: define your plugin interface as a header file (will probably contain the declaration of a plugin initialization function/class, a configuration base class interface and class factory, ...


1

The syntax is quite similar. You will find the ++ operator in both languages. Many of the keywords are the same and have similar (or the same) meanings. However they are both different languages. C++ was developed from the C language, by adding object-orientation on to it. Java was developed as an object-oriented language from the start, and operates in ...


3

Java and C and C++ have some superficially similar syntax traits (several keywords and lexical conventions in common; use of blocks with braces, ...), because both Java and C++ got a lot of inspiration from the C programming language. However, Java and C++ are very different languages. Not only their syntax, but also their semantics are very different. ...


5

In most plugin systems in C and C++, the loading of plugins works like this: The main application specifies a path where the plugins should be located (or allows such a path to be configured). On startup, the application looks for either dynamically loadable libraries (DLLs on Windows, .so on Linux, in case of compiled plugins) or scripts (in case of ...


2

1) Let's assume that t.count() is a linear-time operation with respect to the size of the bitset (it probably isn't on real hardware, but ignore that). Then it would be correct to say that the algorithm is O(M*N^2), for the obvious reason that you have an M-iteration-loop (t.count()) inside an N-iteration-loop inside an N-iteration-loop. That might be ...


2

There are the features that the language provides, and there are other features that the OS provides. iostream for example is built in to the language. conio.h is specific to Windows. There are other headers too that are specific to Linux.


3

You could also be interested in the system programming aspect of your task. Then read Advanced Linux Programming, read the intro(2) & syscalls(2) man pages. Be aware of the POSIX standard. For thread programming, read a good Posix thread tutorial or a C++11 thread tutorial. Regarding C++ programming, the Qt and POCO projects should interest you (and ...


1

The reason you find differences is that the C you are using is not GNU C or ANSI C. It's better if you learn the language well instead of trying to find the differences. I'd suggest referring C: The C Programming Language, 2nd Edition by Brian W. Kernighan and Dennis M. Ritchie C++: The C++ Programming Language (3rd Edition) by Bjarne Stroustrup


-1

You could build the scripting language into the engine so that the engine can take some file formatted in your language and invent some grammars for your program to compile these script files during run-time and use a stack to push method calls, variable declarations etc. like a normal running program though I think it limits your scripting language to only ...


22

Here is what Stroustrup says: In C, you can implicitly convert a void* to a T*. This is unsafe He then goes on to show an example of how void* can be dangerous and says: ... Consequently, in C++, to get a T* from a void* you need an explicit cast. ... Finally, he notes: One of the most common uses of this unsafe conversion in C is to assign ...


1

By definition, A void pointer can point to anything. Any pointer can be converted to a void pointer and thus, you will be able to convert back arriving at the exact same value. However, pointers to other types may have constraints, such as alignment restrictions. For example, imagine an architecture where characters can occupy any memory address but integers ...


31

Because implicit type conversions are usually unsafe, and C++ takes a more safe stance to typing than C does. C will usually allow implicit conversions, even if most chances are that the conversion is an error. That's because C assumes that the programmer knows exactly what they are doing, and if not, it is the programmer's problem, not the compiler's ...


9

In C, there is no need to cast a void * to any other pointer type, it is always safely promoted. It's always promoted, yes, but hardly safely. C++ disables this behaviour precisely because it attempts to have a safer type system than C, and this behaviour is not safe. Consider in general these 3 approaches to type conversion: force the user to ...


-2

I wanted to use this for my thesis project next year, [...] Using a mobile game for your thesis is non-trivial (you will probably need your project's documentation to include game theory and what not (I think this is how Tetris was invented). Good luck! [...] and possibly a way to pay back college loans. Steps: write game ??? proffit In short, ...



Top 50 recent answers are included