Suppose I have something like this:
struct EmptyClass{};
template<typename T1, typename T2 = EmptyClass,
typename T3 = EmptyClass, typename T4 = EmptyClass,
..., typename T20> class PoorMansTuple {
T1 t1;
T2 t2;
...
T20 t20;
};
Now, I may waste up to 19bytes per PoorMansTuple.
Question is:
1) Is there a way...
I know this looks like a silly question, but using object oriented stuff with templates in C++ is really troublesome.
For example, Foo is the base class:
template <typename T>
class Foo {
public:
virtual void Method1() { }
virtual void Method1(int a) { }
virtual void Method2() { }
virtual void Method2(int a) { }
//...
Is it possible to write a class:
template<typename T, ... name> struct Magic {
T name;
};
such that:
Magic<int, foo> gives:
Magic<int, foo> {
int foo;
}
and
Magic<float, bar> gives:
Magic<float, bar> {
float bar;
}
Basically, I want to be able to specify not only the Type, but also the name of the member variables.
...
I think modular is the correct term; to give a basic example if I was to create an encryption application which you could type in like notepad, and then save encrypted, however under the save menu there are options to save for the encryption methods that you have plugins for like AES, Blowfish etc, and also allow new methods to be coded ...
I am new to C++ and I am trying to understand some code. What does it mean to have a * in front of the datatype ? and why is the class Name in front of the method name CAStar::LinkChild
void CAStar::LinkChild(_asNode *node, _asNode *temp)
{
}
...
I'm building a small interpreter so I wanted to test how fast ifs, switch and pointers to functions are, compared to each other. if with 19 else ifs is slightly faster than switch with 20 cases, and function pointers (an array of 20 function pointers) is way slower than the previous two...
I expected the results to be completely opposit...
Hi,
I need to swap a couple of integers in the format int i[2] using a void swap(int& x) function. As you see the function takes an argument of type int&. Here is non-working version of the function:
int i[2] = {3, 7};
void swap (int& x)
{
int temp;
temp = x[1];
x[1] = x[0];
x[0] = temp;
}
int main()
{
cout << i[0...
Could anyone explain the details in terms of rvalues, lvalues, PODs, and non-PODs the reason why the first expression marked below is not ok while the second expression marked below is ok? In my understanding both int() and A() should be rvalues, no?
struct A {};
int main()
{
int i;
A a;
int() = i; //Not OK (error).
A() = a;...
In XNA, you can do
texture = new Texture2D( GraphicsDevice, width, height ) ;
I'm guessing somewhere deep down in the MSFT bowels, this is equivalent to C++ code:
D3DXCreateTexture( GraphicsDevice, width, height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &texture ) ;
In XNA there's this nifty function that lets you set the pixel valu...
When having a base class with pure virtual methods this makes it so that the class can not be instantiated. If I have regular methods and attributes in this base class does the derived classes still inherit those as normal?
For e.g. a getter and setter for an attribute.
...
There is a possibility to compile BOOST libraries in the so-called thread-aware mode. If so you will see "...-mt..." appeared in the library name. I can't understand what it gives me and when do I need to use such mode? Does it give me any benefits?
More than that I'm really confused by having BOOST Threads library compiled in NO-thre...
The following code returns this: error: expected unqualified-id before ‘for’
I can't find what is causing the error. Thanks for the help!
#include<iostream>
using namespace std;
const int num_months = 12;
struct month {
string name;
int n_days;
};
month *months = new month [num_months];
string m[] = {"Jan", "Feb", "Mar", "...
I have a encoded character buffer array of size 512 in c, and a database field of varchar in mysql. Is it possible to store the encoded char buffer into varchar. I have try this but the problem which i face that it only store the limited area of buffer into database and ignore. Kindly guide me that what is the actual problem is, and how ...
I have a problem with setting the size of my array. In my code I have:
class Test {
public:
....//Functions
private:
string name[];
};
Test() {
//heres where i want to declare the size of the array
}
Is this possible?
...
Dear experts,
I have a a mesh, with certain types of elements (e.g. triangular, tetra). For each element I know all its vertices i.e. a triangular 2D element will have 3 vertices v1, v2 and v3 whose x,y,z coords are known.
Question 1
I am looking for an algorithm that will return all the edges... in this case:
edge(v1, v2), edge(v1,...
Hi,
Iam tring to deploy my C# dll in C++, by converting it .tlb. But, while im importing it into C++ program, using the statement
#import "MyProject.tlb" named_guids raw_interfaces_only
Iam geting the error
intellisense cannot open source file " c:/.../debug/MyProject.tlh"
bad descriptor for file.
Also getting the warning:
...
I am getting a segmentation fault in some C code, and I cannot figure out how to read this so I can figure out the problem..
Does anyone have any techniques that can help me? Does anything jump out to you?
Here is gdb output:
GNU gdb 6.8 for GNAT Pro 6.2.1 (20090115) [rev:143235]
Copyright (C) 2008 Free Software Foundation, Inc.
Lic...
How can I convert between local and UTC time (in particular, from local to UTC) using boost::date_time using a current system timezone? I know about boost::date_time::local_adjustor, but it requires a template argument which is a timezone-dependent offset.
Failing platform-independent way to do that, how would I do it specifically on Li...
I need help in understanding the following c++ code (in a .h file):
bool setFontDescription(const FontDescription& v)
{
if (inherited->font.fontDescription() != v) {
inherited.access()->font = Font(v, inherited->font.letterSpacing(), inherited->font.wordSpacing());
return true;
}
retur...
Hi all,
I'm using Visual Studio 2008 (C++). How do I create a CString (in a non-Unicode app) from a byte array that has a string encoded in UTF8 in it?
Thanks,
kreb
EDIT: Clarification: I guess what I'm asking is.. CStringA doesn't seem to be able to interpret a UTF8 string as UTF8, but rather as ASCII or the current codepage (I th...