c++

C++ Templates - LinkedList

Hello, EDIT -- Answered below, missed the angled braces. Thanks all. I have been attempting to write a rudimentary singly linked list, which I can use in other programs. I wish it to be able to work with built-in and user defined types, meaning it must be templated. Due to this my node must also be templated, as I do not know the info...

How to secure communication between two c++ programs over ssh

This might be a non-programming question. Exposition: 1) I am using Linux. 2) I have two C++ programs, "client" and "server"; they run on different machines, they currently talk over tcpip. I have the source code to both programs. 3) Neither program does buffer over flow checking / defense against man in the middle atacks / mac / enc...

2D vector modelling for game development

Making my Asteroids clone (in C) I've rather fallen in love with vector-based entities, but I've simply coded them in as x,y-point arrays. That's been fine for something like Asteroids, but what should I do if I want to make more complex 2D models? I note that there is an awful lot of 3D modelling software out there, as well as ample tu...

Initializiation confusion

Not sure of the appropriate title, but it stems from this discussion: http://stackoverflow.com/questions/620137/syntax-of-new/620402#620402 On Visual Studio 2008, when I run the following code: struct Stan { float man; }; int main() { Stan *s1 = new Stan; Stan *s2 = new Stan(); } Examining the locals, s1 has an uniniti...

ublas matrix expression tutorial/examples

hi I am trying to implement certain matrix operations but I am lost in the internals of ublas library. is there a resource such as tutorial or an example on how to implement new ublas matrix expressions? Thanks ...

Having a class with no data members good option for file manipulation?

I have a file with saved data that sometimes needs to be accessed, written to, erased, etc. when the program is running. I decided to write a SavedDataHandler class to accomplish this. I'm currently using the fstream class. I considered having one data member be the fstream itself, opening it in the constructor, and closing it in the d...

How to print the return type of a function in Visual Studio 2008 (C++)?

Imagine you have a function, if you hover over it with the mouse in visual studio you'll get the function prototype. Is it possible to print to the screen the return type of this function ? This is a practical question, not a programming one. Does the functionality exist in VS ? ...

In a C++ template function can I return a dereferenced argument type ?

What I mean is the following. I want a template function that takes two vector iterators (or two pointers to array of double) and returns a double that is somehow related to the vector iterators or array pointers that I pass. However, I want this to work for double or int, or any arithmetic type. I think I'm not allowed to say: templat...

Converting a Char to Its Int Representation

I don't see this an option in things like sprintf(). How would I convert the letter F to 255? Basically the reverse operation of conversion using the %x format in sprintf? I am assuming this is something simple I'm missing. ...

C++ smart pointer const correctness

I have a few containers in a class, for example, vector or map which contain shared_ptr's to objects living on the heap. For example template <typename T> class MyExample { public: private: vector<tr1::shared_ptr<T> > vec; map<tr1::shared_ptr<T> , int> h; }; I want to have a public interface of this class that sometimes returns sh...

Why does my simple C++ GUI application show a message box in Chinese?

Oh as for the whole (LPCWSTR) casting thing: It wouldn't compile unless I put those in. It game me this error message: Error 1 error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [22]' to 'LPCWSTR' ...

Invoke function within class method from outside the class with name the same like one method in class has

Is there a simple way to invoke the function within some class method from outside the class with name the same like one method in class has. I have 3 different examples. void a () { // outside the class } class A { // example 1, the same names void a() { a (); // but the outside one, } // example 2, differen...

Dangers of Windows API and Administrator accounts?

I wrote a game server plugin last night that allowed me to create a user account and set it as administrator, which is a huge problem. Of course the simple fix is to create a basic user account with limited privileges for the game servers, so they would not have access to do things like this. I wanted to find out if there's anything els...

What does this compiler build statement mean?

Hi everybody, I am a programming student in my second OOP class, which is taught in C++, and I am using Visual Studio 2008. I keep encountering this weird statement when I build my project in VS, my project builds fine, I would just like to know what it means. It appears every time I build my project, doesn't matter if I click rebuild...

Factory, Abstract Factory and Factory Method

Hi, I am really confused about these three terms. My understanding is that: in the Factory pattern, there is no concrete factory. The factory builds the new objects according to the parameters. in Abstract Factory pattern, there are multiple concrete factories. The client has to create different concrete factories explicitly. Is...

Simpler way to create a C++ memorystream from (char*, size_t), without copying the data?

I couldn't find anything ready-made, so I came up with: class membuf : public basic_streambuf<char> { public: membuf(char* p, size_t n) { setg(p, p, p + n) } } Usage: char *mybuffer; size_t length; // ... allocate "mybuffer", put data into it, set "length" membuf mb(mybuffer, length); istream reader(&mb); // use "reader" I...

How do I use chi square distribution with C++ Boost library?

I've checked the examples in the Boost website, but they are not what I'm looking for. To put it simple, I want to see if a number on a die is favored, using 600 rolls, so the average appearances of every number (1 through 6) should be 100. And I want to use the chi square distribution to check if the die is fair. Help!, how would I d...

View return value?

Say I have the following int num = 40 + str2Int("30"); Is there anyway with visual studio 2008 to tell what Str2Int is returning without stepping into the function and going to the return? ...

multiple web cams in AMCap

Hi, I built the AMCap sample under direct show in SDK. It is able to handle 2 or more web cam, how do I modify the program for me to use them simultaneously… like press one button that says ‘start capture’ and make sure that all the cameras start capturing and one button that says ‘stop capture’ to stop all the cameras. i want the frame...

Is it good programming to have lots of singleton classes in a project?

I have a few classes in a project that should be created only once. What is the best way to do that?, They can be created as static object. Can be created as singleton Can be created as global. What is the best design pattern to implement this? I am thinking of creating all classes as singleton, but that would create lot of singlet...