I was unable to find a clear answer to this although that might be because I was not using the proper search terms so please redirect me if that is the case. Is it possible to use previous arguments in a functions parameter list as the default value for later arguments in the parameter list? For instance,
void f( int a, int b = a, int...
I've been using C++ for a bit now. I'm just never sure how the memory management works, so here it goes:
I'm first of all unsure how memory is unallocated in a function, ex:
int addTwo(int num)
{
int temp = 2;
num += temp;
return num;
}
So in this example, would temp be removed from memory after the function ends? If not,...
Hello everyone!
I often come accross the problem that I have a class that has a pair of Register/Unregister-kind-of-methods. e.g.:
class Log {
public:
void AddSink( ostream & Sink );
void RemoveSink( ostream & Sink );
};
This applies to several different cases, like the Observer pattern or related stuff. My concern is, how sa...
The question is pretty much fully embedded in the title.
...
I have a DLL which needs to access data stored in STL containers in the host application. Because C++ has no standard ABI, and I want to support different compilers, the interface between the application and DLL basically has to remain plain-old-data.
For vectors this is relatively straightforward. You can simply return the memory blo...
Hi all,
I've read a bunch of posts regarding redirecting std::cout to stringstreams, but I'm having problem reading the redirected string.
std::stringstream redirectStream;
std::cout.rdbuf( redirectStream.rdbuf() );
std::cout << "Hello1\n";
std::cout << "Hello2\n";
while(std::getline(redirectStream, str))
{
// This does not work - ...
What's the proper way for the main GUI thread to update a QProgressDialog while waiting for a QFuture. Specifically, what goes in this loop:
QProgressDialog pd(...);
QFuture f = ...;
while (!f.isFinished()) {
pd.setValue(f.progressValue());
// what goes here?
}
Right now I have a sleep() like call there, but that's not optimal (...
is it okay( and legal) to delete a pointer that has been passed as a function argument such as this:
#include<iostream>
class test_class{
public:
test_class():h(9){}
int h;
~test_class(){std::cout<<"deleted";}
};
void delete_test(test_class* pointer_2){
delete pointer_2;
}
int main(){
test_class* pointer_1;
w...
I am working with 2 PCs, both running both running Windows XP. Both have the same application registered with its DCOM interface. Now i'm trying to start the program from one computer on the other.
First I called CoInitializeSecurity, after that CoCreateInstanceEx, but the result is a E_ACCESSDENIED.
I did also run dcomcnfg, to give an...
In Linux for example when i use batch if error code is 0 thats good, but what is the convention in C++ ?
when int (or bool) is equal to one we say that's true, but what must be the return of such function in C++ ?
...
I'm trying to remove functions that are not used from a C++ project. Over time it's become bloated and I'm looking to remove functions that aren't used at all.
I have all the projects in a solution file in Visual Studio, but I use cmake so I can generate project files for another IDE if necessary (which is why this isn't tagged with vi...
Hi,
I have a MFC application created by the MFC Project Wizard. I wanted to save/read application settings in the registry and so asked this question to find a C++ Registry wrapper as the Windows API is very messy. However, I have now heard that the MFC provides a way to do this. Is this true? If so, how can I read/write values, see whe...
This problem is related to the Evil delay question, except that my delay is not in launching the application but in waiting for ShellExecute to return.
I have a small dialog application (Win32, written in VC++ 6, running on WinXP) that spawns a worker thread which writes to a logging text file. The thread exchanges information with the m...
Let's say that I want to get the size in bytes or in chars for the name field from:
struct record
{
int id;
TCHAR name [50];
};
sizeof(record.name) does not work.
...
Dear developers,
I have a questions about C++ templates. More specifally, by using template arguments for inheritance.
I am facing strange behaviour in a closed-source 3rd party library. There is a C method
factoryReg(const char*, ICallback*)
which allows to register a subclass of ICallback and overwrite the (simplified) methods:
cl...
i want to terminate the input at '=' character for example that i have given the input 2 +3=
as soon as i give the '=' character it should process the input and display the output.
Any help.. Spaces can also be included in the input. (it should not take any input after '=' character) the pl is c++ or c
...
Is there a good reason why this program compiles under GCC even with the -ansi and -pedantic flags?
#include <cmath>
int main (int argc, char *argv [])
{
double x = 0.5;
return static_cast<int>(round(x));
}
This compiles clean (no warnings, even) with g++ -ansi -pedantic -Wall test.cpp -o test.
I see two problems:
round...
I have some code that 100% works for the use case I have. I'm just wondering if anyone can explain how and why it works.
I have a template class that sits between some code that handles threading and network communication and the library user to pass data received from the server to the user.
template <class Bar,
class Baz...
Given two vectors of integers, how to determinate if there's some element from 1st vector is present in 2nd one?
...
Why tuple documentation for example says to use:
#include "boost/tuple/tuple.hpp"
and not
#include <boost/tuple/tuple.hpp>
I know that it's almost not probably my code will have also boost/tuple/tuple.hpp,
but using include <> states explicitly not to look in the curent directory.
So what is the reason?
...