With wxWidgets I use the following code:
HWND main_window = ...
...
wxWindow *w = new wxWindow();
wxWindow *window = w->CreateWindowFromHWND(0, (WXHWND) main_window);
How do I do the same thing in Qt? The HWND is the handle of the window I want as the parent window for the new QtWidget.
...
The VS2008 SP1 documentation talks about std::tr1::mem_fun.
So why, when I try and use std::tr1::mem_fun, why do I get this compile error?:
'mem_fun' : is not a member of 'std::tr1'
At the same time, I can use std::tr1::function without problems.
Here is the sample code I am trying to compile, which is supposed to call TakesInt on a...
class String
{
private:
char* rep;
public:
String (const char*);
void toUpper() const;
};
String :: String (const char* s)
{
rep = new char [strlen(s)+1];
strcpy (rep, s);
}
void String :: toUpper () const
{
for (int i = 0; rep [i]; i++)
rep[i] = toupper(rep[i]);
}
int main ()
{
...
Should operations that could take some time be performed in a constructor or should the object be constructed and then initialised later.
For example when constructing an object that represents a directory structure should the population of the object and its children be done in the constructor. Clearly, a directory can contain director...
Is there a good way in C++ to implement (or fake) a type for a generic vector of vectors?
Ignore the issue of when a vector of vectors is a good idea (unless there's something equivalent which is always better). Assume that it does accurately model the problem, and that a matrix does not accurately model the problem. Assume also that te...
I'm hosting an Internet Explorer instance (the Web Control) in an CAxWindow ATL class. How do I prevent that a website could open a new window from the hosted IE? I'm already setting an implementation of IDocHostUIHandlerDispatch to disable the context menu.
...
When comparing two objects (of the same type), it makes sense to have a compare function which takes another instance of the same class. If I implement this as a virtual function in the base class, then the signature of the function has to reference the base class in derived classes also. What is the elegant way to tackle this? Should th...
What are some C++ related idioms, misconceptions, and gotchas that you've learnt from experience?
An example:
class A
{
public:
char s[1024];
char *p;
A::A()
{
p = s;
}
void changeS() const
{
p[0] = 'a';
}
};
Even know changeS is a const member function, it is changing the value of the object. So a cons...
I have class with a member function that takes a default argument.
struct Class
{
void member(int n = 0)
{}
};
By means of std::tr1::mem_fn I can invoke it:
Class object;
std::tr1::mem_fn(&Class::member)(object,10);
That said, if I want to invoke the callable member on the object with the default argument, what's the corre...
How would you call the constructor of the following class in these three situations: Global objects, arrays of objects, and objects contained in another class/struct?
The class with the constructor (used in all three examples):
class Foo {
public:
Foo(int a) { b = a; }
private:
int b;
};
And here are my attem...
Hello,
I am looking for a simple C++ library for tokenizing and parsing RTF (Rich Text Format) files. I am planning to edit them with Qt's QTextEdit.
More the Formatting preserved the better -- but actually I am planning to use Bold and Italics only.
In perl I would use RTF::Tokenizer.
It would be nice if the module had some sort of ...
I'm generating C++ code, and it seems like it's going to get very messy, even my simple generating classes already have tons of special cases. Here is the code as it stands now: http://github.com/alex/alex-s-language/tree/local%2Fcpp-generation/alexs_lang/cpp .
...
I am searching for this magazine for quite a long time and I can`t find it.
Any ideas?
...
Sorry for the newb question. I'm still learning programming. So I'm using C++, and I need to do something like this:
int n;
do {
n = get_data();
if(n != -1)
send(n);
} while(n != -1);
This is just a sketch. Anyway it doesn't feel real elegant. I have to have my test twice. I could just test once and set a flag, bu...
Here's a fun exercise.
http://www.hughchou.org/hugh/grid_game.cgi?CLEAR
Who can write the most elegant yet performant code to win this game? My solution is in C/C++.
#include<vector>
#include<iostream>
#include<fstream>
#define N 64
std::vector<int> numbers(N+1);
void init()
{
for(int i = 0; i < N+1; ++i)
numbers[i] = 1;
...
Hey!!
I am trying to resolve Euler Problem 18 -> http://projecteuler.net/index.php?section=problems&id=18
I am trying to do this with c++ (I am relearning it and euler problems make for good learning/searching material)
#include <iostream>
using namespace std;
long long unsigned countNums(short,short,short array[][15],short,boo...
The application de-serializes a stream into dynamically allocated objects and then keeps base type pointers in a linked list (i.e. abstract factory). It's too slow. Profiling says all the time is spent in operator new.
Notes: The application already uses a custom memory allocator that does pooling. The compiler is VC++ 6.0 and the co...
I find myself attached to a project to integerate an interpreter into an existing application. The language to be interpreted is a derivative of Lisp, with application-specific builtins. Individual 'programs' will be run batch-style in the application.
I'm surprised that over the years I've written a couple of compilers, and several dat...
Do you have to pass delete the same pointer that was returned by new, or can you pass it a pointer to one of the classes base types? For example:
class Base
{
public:
virtual ~Base();
...
};
class IFoo
{
public:
virtual ~IFoo() {}
virtual void DoSomething() = 0;
};
class Bar : public Base, public IFoo
{
public:
vi...
In the application that I am working on, the logging facility makes use of sprintf to format the text that gets written to file. So, something like:
char buffer[512];
sprintf(buffer, ... );
This sometimes causes problems when the message that gets sent in becomes too big for the manually allocated buffer.
Is there a way to get sprint...