Sometimes, C++'s notion of privacy just baffles me :-)
class Foo
{
struct Bar;
Bar* p;
public:
Bar* operator->() const
{
return p;
}
};
struct Foo::Bar
{
void baz()
{
std::cout << "inside baz\n";
}
};
int main()
{
Foo::Bar b; // error: 'struct Foo::Bar' is private within this con...
I have an array of 1000-2000 elements which are pointers to objects. I want to keep my array sorted and obviously I want to do this as quick as possible. They are sorted by a member and not allocated contiguously so assume a cache miss whenever I access the sort-by member.
Currently I'm sorting on-demand rather than on-add, but because ...
I have a base class MessageHandler and 2 derived classes, MessageHandler_CB and MessageHandler_DQ.
The derived classes redefine the handleMessage(...) method. MH_DQ processes a message and puts the result in a deque while MH_CB processes the message and then executes a callback function.
The base class has a static callback functio...
I'm looking for a good understandable example in c++ with differences. Does the header file <list.h> provide both or should I look somewhere else?
...
I don't use correctly the format specifiers in C. A few lines of code:
int main()
{
char dest[]="stack";
unsigned short val = 500;
char c = 'a';
char* final = (char*) malloc(strlen(dest) + 6);
snprintf(final, strlen(dest)+6, "%c%c%hd%c%c%s", c, c, val, c, c, dest);
printf("%s\n", final...
Hello. My Vertex Buffer Object code is supposed to render textures nicely but instead the textures are being rendered oddly with some triangle shapes.
What happens - http://godofgod.co.uk/my_files/wrong.png
What is supposed to happen - http://godofgod.co.uk/my_files/right.png
This function creates the VBO and sets the vertex and textu...
Is there anything wrong with the optimization of overloading the global operator new to round up all allocations to the next power of two? Theoretically, this would lower fragmentation at the cost of higher worst-case memory consumption, but does the OS already have redundant behavior with this technique, or does it do its best to conser...
I was converting a struct to a class so I could enforce a setter interface for my variables.
I did not want to change all of the instances where the variable was read, though.
So I converted this:
struct foo_t {
int x;
float y;
};
to this:
class foo_t {
int _x;
float _y;
public:
foot_t() : x(_x), y(_y) { set(0, 0...
I've got a class that has a tr1::shared_ptr as a member, like so:
class Foo
{
std::tr1::shared_ptr<TCODBsp> bsp;
void Bar();
}
In member function Bar, I try to assign it like this:
bsp = newTCODBsp(x,y,w,h);
g++ then gives me this error
no match for ‘operator=’ in ‘((yarl::mapGen::MapGenerator*)this)->yarl::mapGen::MapGene...
I have a short integer variable called s_int that holds value = 2
unsighed short s_int = 2;
I want to copy this number to a char array to the first and second position of a char array.
Let's say we have char buffer[10];. We want the two bytes of s_int to be copied at buffer[0] and buffer[1].
How can I do it?
...
I have some code which gets the short name from a file path, using GetShortNameW(), and then later retrieves the long name view GetLongNameA().
The original file is of the form
"C:/ProgramData/My Folder/File.ext"
However, following conversion to short, then back to long, the filename becomes
"C:/Program Files/My Folder/Filename.ext"....
Hello,
Im using wxWidgets and I call function which takes a long time to proceed. I would like to do it in background.
How can I do that?
Thanks for help
...
Hi,
I know what is my mistake can't figer how to solve it.
Im writing an winAPI that counts how many 'a' characters are found is a givien file.
Im still getting the error " subscript requires array or pointer " (please find the comment in the code)
#include "stdafx.h"
#include <windows.h>
int _tmain(int argc, _TCHAR* argv[])
{
WC...
I'm looking into creating a GUI program for Windows in C++, I have a good knowledge of C++ in the command line and also in game creation. But I'm not sure where to start with GUI application development.
I have Visual Studio 2010 and have created new projects with a GUI but these templates are complex and leaves me not understanding wh...
Today, I wrote some code that needed to add elements to different container variables depending on the type of a template parameter. I solved it by writing a friend helper class specialized on its own template parameter which had a member variable of the original class. It saved me a few hundred lines of repeating myself without adding...
I was wondering if it was safe to make GL calls with multiple threads. Basically I'm using a GLUtesselator and was wondering if I could divide the objects to draw into 4 and assign a thread to each one.
I'm just wondering if this would cause trouble since the tesselator uses callback functions. Can 2 threads run the same callback at th...
I'm using a library that manipulates a binary search tree. In this library is a function that traverses the tree and passes each node it finds to a callback class:
bool TCODBsp::traverseInvertedLevelOrder(ITCODBspCallback *callback, void *userData)
ITCODBspCallback is a base class in the library from which the user is supposed to deri...
Hi All,
Below is a simple program in c++0x that makes use of packaged_task and futures. while compiling the program i get error : variable 'std::packaged_task pt1' has initializer but incomplete type
the program is below
#include <future>
#include <iostream>
using namespace std;
int printFn()
{
for(int i = 0; i < 100; i++)
...
What do I use to perform a case-insensitive comparison on two UTF-8 encoded sub-strings? Essentially, I'm looking for a strnicmp function for UTF-8.
...
I'm getting ( http://www.hdfgroup.org/projects/hdf.net/)
The specified module could not be
found. (Exception from HRESULT:
0x8007007E)
from the dependency walker i'm seeing that SZLIBDLL.DLL is missing i tried to download it from random place but then i got another error.
Does any one had that problem? i tried also vs2005 and ...