c++

save gdb display to a variable

Is there a way to store the output of the last command in gdb to a string? What I would like to do is store the address information of selected machine level instructions. Redirecting the output is not a solution as it would generate too much output. A simulator would also be a solution, but I'd like to see if it would be possible with g...

remove_vertex when the graph VertexList=vecS

I have a Boost Graph with VertexList=vecS. typedef adjacency_list <listS, vecS, undirectedS, TrackInformation, LinkInformation> TracksConnectionGraph; Now I want to iterate through my vertices and remove those that have a specific property. How can I do this? The problem is whenever I call remove_vertex, the iterator to the vertices ...

Can I combine setter and getter in one method, in C++?

I would like to combine setter/getter in one method, in C++, in order to be able to do the following: Foo f; f.name("Smith"); BOOST_CHECK_EQUAL("Smith", f.name()); I don't know how can I declare such a method inside Foo class: class Foo { public: // how to set default value?? const string& name(const string& n /* = ??? */) { ...

Operator overloading

From language design point of view , What type of practice is supporting operator overloading? What are the pros & cons (if any) ? ...

C++ Forward declaration , friend function problem

#include <iostream> class B; class A{ int a; public: friend void B::frndA(); }; class B{ int b; public: void frndA(); }; void B::frndA(){ A obj; std::cout << "A.a = " << obj.a << std::endl; } int main() { return 0; } When I am trying to compile this code some error occurred. Can anyone explain what are the problems in this ...

Deletion of objects send by signals, Ownership of objects in signals, Qt

Here, my signal declaration: signals: void mySignal(MyClass *); And how I'm using it: MyClass *myObject=new myClass(); emit mySignal(myObject); Here comes my problem: Who is responsible for deletion of myObject: 1-)Sender code, what if it deletes before myObject is used? Dangling Pointer 2-)The slot connected to signal, what ...

How can I embed a licence.licx file in a cpp executable?

We are using a third party UI component which requires a licence.licx file. The problem is that the executable is a cpp project and embedding the licence.licx file into the dll which actually uses the third party component does not seem to work. By "does not work" I mean that we get runtime licensing errors when executing the program on ...

Is using implicit conversion for an upcast instead of QueryInterface() legal with multiple inheritance?

Assume I have a class implementing two or more COM interfaces (exactly as here): class CMyClass : public IInterface1, public IInterface2 { }; QueryInterface() must return the same pointer for each request of the same interface (it needs an explicit upcast for proper pointer adjustment): if( iid == __uuidof( IUnknown ) ) { *ppv ...

Help using semphores and threads

I am using the pthread library to simulate a threaded buffer. I am also using semaphores as a solution to accessing critical section variables one at a time. The main problem is that the producer is filling the entire buffer and the consumer is then emptying the entire buffer. Is this code correct? I was assuming that the production a...

new, delete ,malloc & free

This question was asked to me in an interview: In C++, what if we allocate memory using malloc and use delete to free that allocated memory? what if we allocate the memory using new and free it using free? What are the problems that we would face if the above things are used in the code? My answer was there is no...

Problem writing and reading to a text file

Can Some one help me the problem with this code ? I am getting bunch of garbage value ! fstream fs("hello.txt"); if(fs.is_open()) { string s="hello"; string line; fs<<s; while(getline(fs,line)) { cout<<line; } cin.get(); } fs.close(); Thank you very much but when I try to do this I am g...

Undefined reference to external variable

Having problems with a custom logging system I've made. I am declaring an ofstream within my main file so that it is accessible by static functions within my class. This works for my static function (ilra_log_enabled). However, this does not work on my overloaded function for the class. I receive a undefined reference to "logfile" error....

Looking for intentionally buggy code snippets

Hey, I'm looking for some database of intentionally buggy code in C++. I want to give a presentation about static code analysis tools, and I want to show some examples in action. ...

fopen problem - too many open files

I have a multithreaded application running on Win XP. At a certain stage one of a threads is failing to open an existing file using fopen function. _get_errno function returns EMFILE which means Too many open files. No more file descriptors are available. FOPEN_MAX for my platform is 20. _getmaxstdio returns 512. I checked this with WinD...

hello world program?

hi How can i create a hello world program? ...

Get previous value of QComboBox, which is in a QTableWidget, when the value is changed

Say I have a QTableWidget and in each row there is a QComboBox and a QSpinBox. Consider that I store their values is a QMap theMap; When comboBoxes value or spin boxes value is being changed I want to update "theMap". So I should know what was the former value of the combo box in order to replace with the new value of the combo box and...

varargs(va_list va_start) doesn't work with pass-by-reference parameter.

Possible Duplicate: Are there gotchas using varargs with reference parameters Hi, I have a problem with varargs. Look at my code(Microsoft Visual Studio 2005 or 2008). #include <stdarg.h> struct Test { int a; }; void T1(int n, ...) { va_list args; va_start(args, n); char* p = va_arg(args, char*); va_end(args); } void T...

qticon only showing on my pc

i made an app in the tray bar with an icon with qt, this is the way i make the icon; trayIcon->setIcon(QIcon("favicon.ico")); but it only show the icon on my pc, when i give the project to somebody else its just invisible. even if i do the next thing; trayIcon->setIcon(QIcon(QDir::currentPath() + "/favicon.ico")); does somebody kno...

How to clear directory contents in c++ on Linux (basically, i want to do 'rm -rf <directorypath>/*'

I am writing a c++ program on Linux (Ubuntu). I would like to delete the contents of a directory. It can be loose files or sub-directories. Essentially, i would like to do something equivalent to rm -rf <path-to-directory>/* Can you suggest the best way of doing this in c++ along with the required headers. Is it possible to do this...

extract every audio-channel in a quicktime file

I want to extract every audio channel in a quicktime movie with the QuickTime-API. That means if the file has 5.1 surround, i want 6 audio files in the end. But at the moment I don't know how to manage that. Until now I have: OSStatus err = noErr; MovieAudioExtractionRef extractionSessionRef = nil; Boolean allChannelsDiscrete = true; in...