Dear Folks,
One of my students asked me this kind of homework with C++ arrays. It seemed quite interesting for me, so, though I have solved this problem, I wanted to share my solution with you and know another variants and opinions. The problem is following:
Problem
It is given a 2D dynamic quadratic matrix (array) A(nxn). It is require...
Hi,
I am re-implementing auto-update mechanism in an application for internal use in our company.
The old system used .exe based installers, which I had to replace with .msi based installer which can work in a Windows Domain. This I have done and works well.
Most of users in our headquarter are members of windows domain, but there ar...
I want to suspend pthreads but apparently, there is no such function as pthread_suspend. I read somewhere about suspending pthreads using mutexes and conditions and used it as following:
#include <pthread.h>
class PThread {
public:
pthread_t myPthread;
pthread_mutex_t m_SuspendMutex;
pthread_cond_t m_ResumeCond;
void start() {
pthread...
Hi,
I recently got a dll that has been implemented by others. I have to use it in my application. In the header file of their class they have the function declaration
void func1() throw (CCustomException);
Now when i compile it am getting the warning,
C++ exception specification ignored
except to indicate a function is not
_...
Possible Duplicate:
Meaning of const last in a C++ method declaration?
Hi
I got a book, where there is written something like:
class Foo
{
public:
int Bar(int random_arg) const
{
// code
}
};
Also, a by-the-way question: why should/shouldn't I use const before argument declarations? What does that chang...
I'm learning about polymorphism, and I am confused by this situation:
Let's say I have the following C++ classes:
class A{
...
virtual void Foo(){
Boo();
}
virtual void Boo(){...}
}
class B : public A{
...
void Foo(){
A::Foo();
}
void Boo(){...}
}
I create an instance of B and call it...
Hi,
I have a library (C++) which has some API functions. One of them is declared as __cdecl, but gets a function poiner from __stdcall. Something like:
typedef int (__stdcall *Func)(unsigned char* buffer);
//...
int ApiFunc(Func funcPtr); //This is __cdecl since it is an 'extern "C"' library and the calling convention is not specified...
Hi,
I am porting some code from C to C++ and I found this code:
if(ErrorCode >= SOME_CONSTANT)
{
Status = RETVAL_OK;
switch ( ErrorCode )
{
default:
Status = RETVAL_FAILED;
break;
}
}
This code generates a compilation warning:
warning C4065: switch statement contains 'default' but no ...
I've inherited a few C++ files and an accompanying makefile, which I'm trying to bring into VS2010 as a solution. I've created an empty project and added the appropriate C++ and header (.hpp) files for one of the makefile targets.
When I try to compile the project, however, I immediately get a large number of C2061 (syntax error identi...
i got this main;
#include <QtGui>
#include <iostream>
using namespace std;
#include "tray.h"
void main(int argc, char *argv[])
{
QApplication app(argc, argv);
Tray iets;
app.exec();
}
when i open in tray something like;
QFileDialog *dialog = new QFileDialog;
QString dir;
QString test = dialog->getOpenFileName(NULL, NU...
A carelessly written template here, some excessive inlining there - it's all too easy to write bloated code in C++. In principle, refactoring to reduce that bloat isn't too hard. The problem is tracing the worst offending templates and inlines - tracing those items that are causing real bloat in real programs.
With that in mind, and bec...
I want to set a machine timer resolution to 0.5ms.
Sysinternal utility reports that the min clock resolution is 0.5ms so it can be done.
P.S. I know how to set it to 1ms.
P.P.S. I changed it from C# to more general question (thanks to Hans)
System timer resolution
...
Hi all,
I have the following function as the constructor for a class:
template<typename T>
void Pointer<T>::Pointer(T* inPtr)
{
mPtr = inPtr;
if (sRefCountMap.find(mPtr) == sRefCountMap.end()) {
sRefCountMap[mPtr] = 1;
} else {
sRefCountMap[mPtr]++;
}
}
Here is the definition for the map:
static std::map<T*, int> s...
I use boost shared_ptr to wrap a pointer. However I can only get the correct value in test_shared_ptr(), while in main(), I get the wrong value.
Expected output:
100
100
Actual output:
100
-572662307
It seems that the pointer becomes invalid in that case. Any correct approach to do the job? Than...
I need to break open a MS Word file (.doc) and extract its constituent files ('[1]CompObj', 'WordDocument' etc). Something like 7-zip can be used to do this manually but I need to do this programatically.
I've gathered that a Word document is an OLE container (hence why 7-zip can be used to view its contents) but I can't work out how to...
Why is this code note working (the code compiles and run fine, but is not actually showing the permutations):
int main(int argc, char *argv[])
{
long number;
vector<long> interval;
vector<long>::const_iterator it;
cout << "Enter number: ";
cin >> number;
while(number-->0){
interval.push_back(number);
...
hi
how can i add "for each" support for my class in c++0x and visual studio 2010?
...
I need to sort some arrays of floats, modify the values, and then construct an array with the original ordering, but the modified values.
In R, I could use the rank() and order() functions to achieve this:
v a vector
v[order(v)] is sorted
v[i] goes in the rank(v)th spot in the sorted vector
Is there some equivalent of these functions...
I'm trying to make a serial connection to an Arduino Diecimila board with QextSerialPort. My application hangs though everytime I call port->open(). The reason I think this is happening is because the Arduino board resets itself everytime a serial connection to it is made. There's a way of not making the board reset described here, but I...
Is there a way to execute a program and receive the console output in c++ instead of displaying the console window? I am trying to do a command line call but provide a GUI instead of the console output.
...