c++

Instantiating template with a variably modified type

Hi, One of my class' member method take as an argument of enumeration type: it produces different side effects for different enum. I was wondering whether it's possible to use template as a lookup table, two possible solutions came up to my mind, but none of them seems to work: //// 1 //// class A { public: enum AEnum : uint...

whats wrong with my c++ boost regex function???

Hello, #include <iostream> #include <algorithm> #include<boost/algorithm/string.hpp> #include<boost/regex.hpp> using namespace std; using namespace boost; string _getBasehtttp(string url) { regex exrp( "^(?:http://)?([^\\/]+)(.*)$" ); match_results<string::const_iterator> what; if( regex_search( url, ...

Help with ifstream in programming test

Hello all, I recently did a programming test in which there was a ifstream section which I could not solve. Since then I have been trying to solve the problem in my free time to no avail. The problem is basically to read from a binary file and extract the information there. Here is the file format: ---------------------------------...

operator overloading

Hi, I've created a class myString and I'm trying to run the following code: class myString{ char* str; int len; public: myString(char* str1 = " "){ len = strlen(str1); str = new char[len+1]; strcpy(str, str1); }; int getLen() const { return len; }; char* getString() const {...

Finding object under mouse

I'm developing a game that basically has its entire terrain made out of AABB boxes. I know the verticies, minimum, and maximum of each box. I also set up my camera like this: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(Camera.rotx,1,0,0); glRotatef(Camera.roty,0,1,0); glRotatef(Camera.rotz,0,0,1); glTranslatef(-Camera.x,-C...

Merge STL map's

How can I merge two STL maps into one? They both have the same key value types (map). If there is overlap of the keys I would like to give preference to one of the maps. ...

Least Recently Used cache using C++

hi, I am trying to implement LRU Cache using C++ . I would like to know what is the best design for implementing them. I know LRU should provide find(), add an element and remove an element. The remove should remove the LRU element. what is the best ADTs to implement this For ex: If I use a map with element as value and time counter as ...

[OpenSSL] SSL_accept() throws "Invalid argument" error

I'm attempting to create a client/server program, but I'm finding some difficulty continuing with the unfortunately sparse amount of OpenSSL documentation. My issue: SSL_accept throws an "Invalid Argument" upon executing the following code (simplified): SSL* ssl = SSL_new(ctx); // ctx is created earlier SSL_set_fd(ssl, socket); // sock...

Two really similar classes in C++ with only one different method: how to implement?

Hi all, I have two classes that are almost identical, besides one method. The classes have the same data part and all the member functions but one: class A { private: double data; public: double calc(){ return data*data; } double especific(){ return 2.0*data; } } and the second class is identical, besides the es...

Iterate through Enums in C++

C++ enum question. So I have a list of files, and their IDs that I need to iterate over, and do stuff to. Most of the stuff is the same, but there are a few file-specific things that need to be done. I tried putting the file IDs in an enum, and iterating over that. Howver, the fileIDs are non contiguous, and jump around. Currently, I ...

GDB can't access mmap()'d kernel allocated memory?

I'm running into an issue with GDB and some buffers allocated in kernel space. The buffers are allocated by a kernel module that is supposed to allocate contiguous blocks of memory, and then memory mapped into userspace via a mmap() call. GDB, however, can't seem to access these blocks at any time. For example, after hitting a breakpo...

Interesting Console Program for C++ beginners

I’m teaching an entry-level C++ programming class. We only use iostream in the class (No GUI). It seems like students are not so excited to printout strings and numbers to their console. (Most students even never used the console before.) It is hard to motivate or convey the excitement of programming by showing strings in their console. ...

what is the convention for calling overloaded = operator in C++ using pointers ??

When overloading a "=" operator for a class, the usual syntax is: ClassA ObjA, ObjB; ObjA = ObjB; But what about pointers ?? Class *PtrA, *PtrB; PtrA->operator=(PtrB) Is the above calling convention correct assuming the = operator in ClassA is defined for pointer on class (ClassA* operator=(const ClassA* obj)) ?? ...

How do I open a dialog and retrieve strings from it, in QT 4?

This is the main window so far and the second window is a dialog window. How do I get the text from a textbox on window2 when it closes? Thanks. #include "mainwindow.h" #include "window2.h" #include "ui_mainwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ...

My first C++ class ( and error )

I tried a naive class taken from a book I found in the office. This is it: #include <iostream.h> #include <math.h> const double ANG_RAD = 0.017; class Angulo { double valor; public: void act_valor( double ); double seno( void ); double coseno( void ); double tangente( void ); } grado; void Angulo::act_valor( double a ) { ...

c++ pass by reference : two level deep function calls

I have code similar to this in c++. It aborts when i try to run it. Would this type of code work ? In the main function : type* a = something type* b = something func1(a,b); func1 declaration: void func1(type* &a, type* &b){ func2(a,b); // do something } func2 is as follows void func2(type* &a, type* &b){ // do somethin...

C++ String to Double parsing with exceptions?

In java, if I wanted to create some application which could receive both doubles and strings as appropriate input, I would probably do the following: String input = getInput();// try { double foo = Double.valueOf(input); //Do stuff with foo here } catch (NumberFormatException e) { //Do other validation with input } How...

C++: scope of for loop?

#include <iostream> using namespace std; int main() { int i; for(i=0; i <= 11; i+=3) cout << i; cout << endl << i << endl; } output is: 0 3 6 and 9 and then once it exits the loop its 12. The addresses of i inside the loop and out appear the same What I need to know is: Is the i inside the for loop the same as the...

Get OpenCV2.1 to run in windows using eclipse

Hi, I am trying to get OpenCV2.1 to run on my windows machine. Here is what I have done so far: Installed MinGW using MinGW-get-inst Installed Visual Studio C++ 2008 Express Installed OpenCV-2.1.0-win32-vs2008.exe downloaded from OpenCV's website Installed Eclipse Then to test everything, I created a new project, and: Configured Ec...

PHP system() args

I have the following code that executes a C++ program and outputs it: <html> <head> <title>C++</title> </head> <body> <div><?php system("app.exe", $out); echo rtrim($out, "0"); ?></div> </body> </html> How can I make it so that you can pass arguments to the c++ program, say like this... If this was the c...