c++

What is the Basic Structure of a Function in FORTRAN?

This is something that's I've wanted to know recently, mostly out of curiousity. I'm in the mood to learn some old coding styles, and FORTRAN seems like a good place to start. I guess I should help you guys out by providing a good starting point. So how would this C procedure be written in FORTRAN? int foo ( int x , int y ) { int...

Best Practice For List of Polymorphic Objects in C++

What is a common practice for the storage of a list of base class pointers each of which can describe a polymorphic derived class? To elaborate and in the interest of a simple example lets assume that I have a set of classes with the following goals: An abstract base class whose purpose is to enforce a common functionality on its deri...

Pattern for objects initialization at startup

I'm building an application and as time goes on, I have more and more objects to initialize at startup. Moveover, some of the newer objects depend on others so I'm getting some kind of spaggetti initialization where objects are created then passed to other constructors. I'm suspecting that I'm getting it wrong. For example I have a WinF...

C++ and Qt - encoding from page-content

Hello. Here is link where i got a code for web-page content fetching. But i have a trouble: i got text in wrong encoding. Could i correct it? Thanks. EDIT: I'm trying to get data from page: http://ru.wiktionary.org/wiki/example And got: EDIT2: I just save all data to the html-file and show it in QWebView. ...

Other's library #define naming conflict

Hard to come up with a proper title for this problem. Anyway... I'm currently working on a GUI for my games in SDL. I've finished the software drawing and was on my way to start on the OpenGL part of it when a weird error came up. I included the "SDL/SDL_opengl.h" header and compile. It throws "error C2039: 'DrawTextW' : is not a member...

Not sure what is causing my segmentation fault - C++

Hi I have some experience with programming but I'm not very good with pointers. I've been trying to debug this program I've been working on but it keeps giving me a segmentation fault. My code is the following: #include <iostream> using namespace std; class hexagon { public: hexagon(); ~hexagon(); void setSide(int side, h...

How to check the length of an input? (C++)

I have a program that allows the user to enter a level number, and then it plays that level: char lvlinput[4]; std::cin.getline(lvlinput, 4) char param_str[20] = "levelplayer.exe " strcat_s(param_str, 20, lvlinput); system(param_str); And the level data is stored in folders \001, \002, \003, etc., etc. However, I have no way of tellin...

Is this a good way to use dlls? (C++?)

I have a system that runs like this: main.exe runs sub.exe runs sub2.exe and etc. and etc... Well, would it be any faster of more efficient to change sub and sub2 to dlls? And if it would, could someone point me in the right direction for making them dlls without changing a lot of the code? ...

Why is msbuild and link.exe "hanging" during a build?

We have a few C++ solutions and we run some build scripts using batch files that call msbuild.exe for each of the configurations in the solutions. This had been working fine on 3 developer machines and one build machine, but then one of the projects started to hang when linking. This only happens on the newest machine which is a quad co...

Including Objective C++ Type in C++ Class Definition

I've got a project that is primarily in C++, but I'm trying to link in a Objective-C++ library. I have a header that looks something like: CPlus.h: #import "OBJCObject.h" class CPlus { OBJCObject *someObj; }; CPlus.mm: CPlus::CPlus() { someObj = [[OBJCObject alloc] init]; } When I import the Objective-C++ header into my code...

C++ - how does Sleep() and cin work?

Just curious. How does actually the function Sleep() work (declared in windows.h)? Maybe not just that implementation, but anyone. With that I mean - how is it implemented? How can it make the code "stop" for a specific time? Also curious about how cin >> and those actually work. What do they do exactly? The only way I know how to "bloc...

How can I combine the factory pattern with code flexibility

I am considering a factory function to create different classes in the same hierarchy. I understand that normally a factory is normally implemented as follows: Person* Person::Create(string type, ...) { // Student, Secretary and Professor are all derived classes of Person if ( type == "student" ) return new Student(...); if ...

Adding a minimize button to a Qt dialog?

I have created a QDialog based app using Qt Creator and all is well other than the dialog has no minimize button. How can I add one? Is there a property in the designer that I can set? ...

What is the simplest RTTI implementation for C++?

I'm trying to implement exception handling for an embedded OS and I'm stuck at how to detect the type of the thrown "exception" (to select the appropriate handler). The saving and restoring context parts of the exception handling are already done, but I can't have specific handles since I can't detect the type of the thrown 'exception'....

Linked List: Is this solution good?

I was looking for a way to avoid starting from the head of the list each time I want to find a node, so I thought of assigning indexes to nodes, keeping a pointer to a random (not exactly random; see below) node and then finding the pointer that's closest to the index I want to find. Allow me to explain with code: // head and last are p...

Why is this a floating point exception?

Today I was tracking down a floating point exception in some code I had just written. It took a little while to find because it was actually caused by taking an integer mod zero. Obviously doing anything mod zero is not going to be defined but I thought it was strange that the error was so misleading. What is it within the C++ modulo ope...

Why should I use asserts?

I never got the idea of asserts -- why should you ever use them? I mean, let's say I were a formula driver and all the asserts were things like security belt, helmet, etc. The tests (in debug) were all okay, but now we want to do racing (release)! Should we drop all security, because there were no issues while testing? I will never...

Why does C++ use pointers?

Why does C++ need and use pointers? I know they add power to the language but they make it a lot harder to understand for beginners. Languages like F#, Java, Ruby, Python, Lua, etc. get by just fine without them, and they're quite powerful. ...

Quick watch window not showing the variable value in Visual Studio for C++/CLI project

I know that Visual Studio support for C++/CLI is terrible. But I am getting a weird issue when doing a Quick watch. The variable which I am watching is in the scope and it has value. But VS says, the variable is not in the scope. See the image It would be great if someone can suggest a workaround. Or is this a bug with VS? ...

Real time video capture??

Hi all, Just as a hobby, I want to capture realtime video. The source of video for a start would be a web camera. I have one from logitech. What I am trying to do is make a custom window with Real time video display as one part and other miscellaneous widgets. As a starting point I looked in Qt and phonon did sound promising. But instal...