I'm using a fairly simple boost::asio set-up, where I call io_service.run() from the main thread.
I have a tcp resolver, and use async resolve to look up an address.
When that look-up fails, I throw an exception inside the asynchronous callback.
I catch this exception outside the run() call, inside the main function. I then call stop() o...
I have the following code:
...
int n;
cin >> n;
int numbers[n];
...
It compiled with netbeans on mac using g++ (I think) and it didn't compile using vs2008 on windoze. Why is it so hard to make it work with every compiler? The size of the array is known before allocating it.
EDIT: I know abot std::vector. Actually this was part of a...
I am compiling on Ubuntu 10.04 LTS. The Perforce Python API uses their C++ API for some of it. So, I point the setup.py at the C++'s API directory using the --apidir= they say to use. When it starts to compile the C++, I get a whole load of errors. Here is the error list... http://pastebin.ca/1907389 ...But anyway, no one else has had th...
Hi,
For some complicated reason, I want to convert any supported type T (coming from a template) to a list of types I have chosen. For this, I tried using a template structure named "Convert". For example:
Convert<short>::type should be int
Convert<int>::type should be int
Convert<char>::type should be int
Convert<float>::type should b...
The error is in this code:
//myutil.h
template <class T, class predicate>
T ConditionalInput(LPSTR inputMessage, LPSTR errorMessage, predicate condition);
//myutil.cpp
template <class T, class Pred>
T ConditionalInput(LPSTR inputMessage, LPSTR errorMessage, Pred condition)
{
T input
cout<< inputMessage;
cin>...
I am little confused about vptr and representation of objects in the memory, and hope you can help me understand the matter better.
Consider B inherits from A and both define virtual functions f(). From what I learned the representation of an object of class B in the memory looks like this:[ vptr | A | B ]
and the vtbl that vptr points...
Hi !
What I'ld like to do is similar to what VS does in its output window or other editors in their tool windows: Start another process B from my process A and capture its stdout/stderr output.
So far, I got it working with CreatePipe(), but for some reason, the output of B doesn't arrive at B right when it gets written. It behaves mor...
Can we increase the re-usability for this key-oriented access-protection pattern:
class SomeKey {
friend class Foo;
// more friends... ?
SomeKey() {}
// possibly non-copyable too
};
class Bar {
public:
void protectedMethod(SomeKey); // only friends of SomeKey have access
};
To avoid continued misunderstandings, ...
Hi. How can I remove a list of selected items in the QListView in QT 4.6.
Something like this does not work, the iterator becomes invalid:
QModelIndexList indexes = ui.listview_files->selectionModel()->selectedIndexes();
foreach(QModelIndex index, indexes)
{
model->removeRow(index.row());
}
removeRows also not suitable, it...
Hi All
I am trying to build small logger library.
I am facig some problem with c++ templates.
Here is what my class structure looks like.
class abstract_logger_t {
public:
typedef abstract_logger_t logger_type;
template<typename data_t>
abstract_logger_t& log(const data_t& data) {
return *this;
}
};
class stdout_logger_t ...
i have implement binary search tree in c++
#include <iostream>
#include <cstdlib>
using namespace std;
class binary{
private:
struct tree{
tree *left;
tree *right;
int data;
};
tree *root;
public:
binary(){
root=NULL;
}
bool empty() { return root=NULL;}
voi...
In the example below, what exactally is the << operator doing? I'm guessing it is not a bitwise operator.
std::cout << "Mouse down @ " << event.getPos() << std::endl;
I understand what the code will do here: Use standard out, send this text, send an end of line. Just I've never come accross the use of this << apart from on raw binary....
Hi all!
I want enchanted syntax coloring in comments for C++ language in Visual Studio 2010. For example, I have the following code:
/*!
\sa testMeToo()
\param a the first argument.
\param s the second argument.
*/
int testMe(int a,const char *s);
In Visual Studio all \param, \sa and other Doxygen commands are not h...
So, I'm just playing around implementing some sorting algorithms in C++, but I'm finding it irritating to benchmark them at the moment, due to the length of time it takes to not run the algorithm, but to create the input data. I currently test each length of input (1000, 2000, ...) 10 times, to gain a somewhat averaged time. For each of ...
I have the following code
int m[4]={1,2,3,4}, *y;
y=m;
*y = f(y++); // Expression A
My friend told me that Expression A has a well defined behavior but I am not sure whether he is correct.
According to him function f() introduces a sequence point in between and hence the behavior is well defined.
Someone please clarify.
P.S: ...
Is there any other way to determine size of the container than :
//those are valid iterators from a container
BidIt begin;
BidIt end;
std::size_t size = 0;
while (begin != end)
{//Here throug iterating I'm getting adventually the correct size
++size;
++begin;
}
but I wonder if I could check size of this container by for example...
I have a couple of files written in C, and I want them to be C++-compatible, so for my C headers I use;
#ifdef __cplusplus
extern "C" {
#endif
at the beginning of the file and of course
#ifdef __cplusplus
}
#endif
...at the end. But it seems to create problems with the 'inline' keyword. My solution is to simply remove the inline k...
I'm looking for a cross-platform library in C/C++ which can schedule jobs, function calls, etc. It would be nice if it is closer to Java Quartz. I would prefer BSD style licenses, LGPL would be okay too.
...
/home/tdlk/src/mingw-w64/superv32/gcc/libjava/win32-threads.cc: In function 'void _Jv_ThreadStart(java::lang::Thread*, _Jv_Thread_t*, void (*)(java::lang::Thread*))':
/home/tdlk/src/mingw-w64/superv32/gcc/libjava/win32-threads.cc:393: error: 'GC_CreateThread' was not declared in this scope
//win32-threads.cc
19 #include <gc.h>
393 d...
i have implement this code from programming pearls and i think it should be correct but it gives me this mistake
code:
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
using std::qsort;
int charcmp(char*x,char *y){ return *x-*y;}
#define wordmax 100
int main(void){
char word[wordmax];
char sig[wo...