c++

Calling functions in external C library from a QT app (win32)

This might be a little QT specific, but here we go... I've got a QT app that I need to interface with a couple of external libraries written in C. Everything seems to be working, as I can link correctly, but when I try and call any function in one of the libraries I always get an access violation error. For the other library, I call l...

Method to return to beginning of function

Does C++ have any type of utility to return to the beginning of a function after a function call? For example, example the call to help() in the calculate function. void help() { cout << "Welcome to this annoying calculator program.\n"; cout << "You can add(+), subtract(-), multiply(*), divide(/),\n"; cout << "find the re...

C++ - Calling a function inside a class with the same name as the class

I was trying to write up a class in c++, and I came across a rather odd problem: calling outside functions inside of a class that have the same name as the class. It's kinda confusing, so here's an example: void A(char* D) { printf(D); } class A { public: A(int B); void C(); }; A::A(int B) { // something here } void A::C() {...

How do I know who holds the shared_ptr<>?

I use boost::shared_ptr in my application in C++. The memory problem is really serious, and the application takes large amount of memory. However, because I put every newed object into a shared_ptr, when the application exits, no memory leaking can be detected. There must be some thing like std::vector<shared_ptr<> > pool holding the r...

Public virtual function derived private in C++

Hello All, I was trying to figure out what happens when a derived class declares a virtual function as private. The following is the program that I wrote #include <iostream> using namespace std; class A { public: virtual void func() { cout<<"A::func called"<<endl; } private: }; class B:public A { public:...

How to get file icon using C++

Hi all, I want to add Icon to treeview node, using C++. I want to get the icons from system, I tried I tried with, PMString ucPath("C:\\path\\to\\file.extension"); SHFILEINFO info; ::SHGetFileInfo(ucPath.GrabTString(), FILE_ATTRIBUTE_NORMAL, &info, sizeof(info), SHGFI_ICON | SHGFI_USEFILEATTRIBUTES | SHGFI_SMALLICON); icon...

lock-free memory reclamation with 64bit pointers

Herlihy and Shavit's book (The Art of Multiprocessor Programming) solution to memory reclamation uses Java's AtomicStampedReference<T>;. To write one in C++ for the x86_64 I imagine requires at least a 12 byte swap operation - 8 for a 64bit pointer and 4 for the int. Is there x86 hardware support for this and if not, any pointers on ho...

C++ : How to write a const_iterator?

I've written my own container template with an iterator. How do I implement const_iterator? template <class T> class my_container { private: ... public: my_container() : ... { } ~my_container() { } class iterator : public std::iterator<std::bidirectional_iterator_tag, T> { public: ... ...

Expression: String iterator not dereferencable

I'm having a hard time using std::string::iterators in C++. This code compiles fine (still not getting correct output, but that's my fault: TODO, fix algorithm) in Dev-C++, and I don't get runtime errors. The error is with Visual Studio Express 2008 C++, where I'm getting an error pointing to < xstring>: "Expression: string iterator not ...

visual c++ 2008 release problem

Hi, I've made a simple C++ program in VC++ 2008 Pro and it runs fine in the pc I used to develop it but when I run it in a pc without VC++ installed, it just gives me a "This application has failed to start because the application configuration is incorrect" error. I fixed this before by statically linking my project but now when I ...

results from debug diff from release

I have this code here: #include "windows.h" #include "Tlhelp32.h" #include "shellapi.h" #include <wchar.h> #include <fstream> bool enumProcesses(); int main() { enumProcesses(); ShellExecute( NULL, L"open", L"log.txt", NULL, NULL, SW_SHOW ); return 0; } bool enumProcesses() { std::wofstream log("log.txt"); PROC...

Error while opening shared object: SunGrid Engine

Hi all, My application uses the Sun N1 grid engine through the API DRMAA present as shared object libdrmaa.so . I am using dlopen and dlsym to acess functions of the library. That works fine. Now if I try to link it form command line the executable is built but executing it gives the error " Cannot open shared object file". Can anyone s...

C++ library with a Java-like API

Hello. Hoping that anybody here knows about a good one: I'm looking for a (free to use) C++ library with a class hierarchy and methods resembling the Java API, with at least the I/O & networking part if it, specifically HTTP handling. I work mainly with C & Java, but for this particular project C++ is recommended, so I thought of adopt...

SetCurrentDirectory in multi-threaded aplication

I understand SetCurrentDirectory shouldn't be used in a multithreaded application since the current directory is shared between all threads in the process. What is the best approach to setting the directory with this in mind. It can mostly be avoided setting the directory by including the full pathname when opening files instead of firs...

Icon click on Qt QTreeWidget

Hello, I have a treewidget in my Qt form. It shows a tree of files, showing a icon representing something about them, and their name. I entered these using treeItem->setIcon(0, *icon), and treeItem->setText(0, text) . The reason I entered both values to the same column (0), is because otherwise the icons would not stay next to the tex...

QTreeView - Sort and Filter a model

Hello I am trying to create a QTreeView which displays some sorted information. To do this I use a QSortFilterProxyModel between the view and my model. The problem is that I want to limit the number of rows to the first n rows (after sorting). The filter function from the model receives the original sourceRow so I cannot use it. I've ...

usage of system function in cpp program

Please explain the syntax of: system(const char *command); I want to use this function for running the command on unix sytem. I need to execute(automate) several test cases with the same command but,they also have other input values which are different.how do I reuse this code for all the test-cases. ...

How to make reverse_graph adaptor from my custom Graph type

I have a Graph type which satisfies concepts: boost::function_requires<boost::GraphConcept<Graph> >(); boost::function_requires<boost::IncidenceGraphConcept<Graph> >(); boost::function_requires<boost::BidirectionalGraphConcept<Graph> >(); boost::function_requires<boost::VertexListGraphConcept<Graph> >(); boost::function_requires<boost::...

Calling a non-returning python function from a python script

Hi, I want to call a wrapped C++ function from a python script which is not returning immediately (in detail: it is a function which starts a QApplication window and the last line in that function is QApplication->exec()). So after that function call I want to move on to my next line in the python script but on executing this script and...

Using Class Template in Visual C++

Hello, I wrote template which return matrix in Window Form Application .My template is below: template<class T> class matrix1 { protected: public: T *data; const unsigned rows, cols, size; matrix1(unsigned r, unsigned c) : rows(r), cols(c), size(r*c) { data = new T[size]; ...