c++

QGraphicsView noobie question

Trying to add text to QGraphicsView: Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui->setupUi(this); QGraphicsScene scene; scene.addText("Hello, world!"); ui->graphicsView->setScene(&scene); } But when the project running, there is nothing on the QGraphicsView. ...

Deleting char array returned by getenv()

Should I free the memory allocated for the char array, pointer to which is returned by the char * getenv( char * ) function? And which way - C free() or C+ delete []? If no - why? I mean: char * ptr = getenv( "LS_COLORS" ); cout << ptr << endl; delete [] ptr; //Is this or free() call needed? Thank you. ...

looking for scripting language for automated build & deploy

I'll start to write a automated build/deploy script for our software team, and I'm not sure which scripting language or tool to use. I'm always eager to learn something new and improve my value on the current software market, so what language do you propose? In the past, I used windows batch files, which are kind of ugly to read and scr...

What should be the right file permissions for program executables and logs files?

I have written a Linux system wide C++ program /usr/bin/PROG_X that uses a configuration file /etc/PROG_X.conf and log file /var/PROG_X.log. Now I need to call this program, after strong authentication, from the web using apache web server and php. Calling the program may involve changing configuration files and will change, of course, ...

2D graphic C++ library / Flash

ADD Here's what I really ask: I need to create complex 2d graphic and input with callbacks on pressing elements. Also it would be generated in run-time. Now try to choose: Flash (nearly all is done: net, graphic, p2p), C++ (lots of external libraries, but good for desctop). But using Flash I can't create exe file: the only way to creat...

Need examples on C++ vector usage

Given the C++ vector as below: vector<double> weight; weight.resize(128, 0); Can weight be used as: weight['A'] = 500.98; weight['P'] = 455.49; What does this mean? And how to use these values? Could anyone give me an example? thank you! ...

Why does VS require constant for array size, and MinGW does not? And is there a way around it?

I have ported some code from Mingw which i wrote using code::blocks, to visual studio and their compiler, it has picked up many errors that my array sizes must be constant! Why does VS need a constant size and mingw does not? e.g. const int len = (strlen(szPath)-20); char szModiPath[len]; the len variable is underlined in red to say...

Problem with conversion

I have a class: template<class T> class MyClass { public: class Iterator { public: Iterator(MyClass<T>&){/*some code*/}; }; operator Iterator(); Iterator& begin(); }; template<class T> MyClass<T>::operator typename MyClass<T>::Iterator() { ret...

C++: Files, encodings and datatypes

---- PLEASE CLOSE ---- ------ Edit --------- I found where the problem is. I'm going to start a new question for the real problem .... ----------------------   Hi, My Situation: Linux (Ubuntu 10.04) gcc But it has to be platform independent I have a text file (UTF-8) with special characters like ¥ © ® Ỳ È Ð. I have a std:...

Writing a library that needs to be object-orientated. Objective-C or C++ for the highest compatibility with C?

I am planning to write an open-source library which really needs to be written in an object-orientated language. One problem is that the library should be possible to use with C, where it doesn't matter of direct inclusion of source code or (dynamic) linking to a precompiled library. I know all three C++, C and Objective-C. Objective...

c++ template of template

#include "boost/numeric/ublas/matrix.hpp" using namespace boost::numeric::ublas; template <class matrixform,class input_T> class Layer { private: matrixform <input_T>; public: }; I want to be able to do int main () { Layer<identity_matrix, double> mylayer; } BUT layer.hpp:18: error: ‘matrixform’ is not a template layer.h...

Is there a place where we can see PHP <=> C++ equilavent libraries/function for a php developer starting with C++?

Is there a place where we can see PHP <=> C++ equilavent libraries/function for a php developer starting with C++? As a PHP developer starting with C++, I often ask myself: what is the equivalent of such-and-such PHP function in C++? The advantage of php, is that we have a very nice site which documents about everything we might want t...

When the virtual member functions of a template class instantiated?

I know that the normal member function of an template class will be instantiated whenever it is used for the first time. But this cannot be done for the virtual member function as it can be accessed through base class pointer. This means that virtual member functions will be instantiated as soon as the tmeplate class is instantiated? If ...

C++: std::string problem

Hi again, I have this simple code: #include <iostream> #include <fstream> using namespace std; int main(void) { ifstream in("file.txt"); string line; while (getline(in, line)) { cout << line << " starts with char: " << line.at(0) << " " << (int) line.at(0) << endl; } in.close(); return 0; } wh...

How to use C++ Smart Pointers?

I've been using C++ for some time now and I still don't feel very comfortable about using smart pointers and I've only been using them when editing some code that uses them, never in my own code (it might be worth to say that I'm a student). Can you explain what are the types of smart pointers, how do they work and when to use them? Al...

algorithm to match prefix and name to a list of names

I have a std::vector<std::string> of all the files in a directory: // fileList folder/file1 folder/file2 file3 file4.ext and a std::set<std::string> of filenames and the same for all used folder prefixes: // set1 file2 file4.ext // set2 folder I need to generate the full (relative) paths to the ALL files in set1, but see no way of...

Const method that modifies *this without const_cast

The following pattern has arisen in a program I'm writing. I hope it's not too contrived, but it manages to mutate a Foo object in the const method Foo::Questionable() const, without use of any const_cast or similar. Basically, Foo stores a reference to FooOwner and vice versa, and in Questionable(), Foo manages to modify itself in a c...

OpenGL Line Width

In my OpenGL app, it won't let me draw a line greater then ten pixels wide. Is there a way to make it draw more than ten pixels? void OGL_Renderer::drawLine(int x, int y, int x2, int y2, int r, int g, int b, int a, int line_width) { glColor4ub(r, g, b, a); glLineWidth((GLfloat)line_width); glBegin(GL_LINES); glVertex2i(x, y); glVe...

Can you please explain this piece of code?

#include <stdio.h> #include CONST15 #define CONST2 CONST2*CONST1 #define CONST3 CONST2+CONST2 int main(int argc,char**argv) { printf("%\n",CONST3); } ...

C++: What's the difference between function(myVar) and (function)myVar ?

This is yet another one of those questions I'd like to be able to tag 'newbie'. I'm going through the full tutorial at cplusplus.com, coding and compiling each example manually. Regularly, I stumble upon something that leaves me perplexed. I am currently learning this section: http://www.cplusplus.com/doc/tutorial/structures/ . There a...