c++

How do you decipher complex declarations of pointers+arrays?

Although I use std::vector almost all the time, I am interested in understanding as much as I can about pointers. Examples of what I am talking about: char* array[5]; // What does it mean? // 1) pointer to an array of 5 elements! // 2) an array of 5 pointers? I am interested in the precise definition of this declaration. ...

What advantages can I get from learning C++ if I'm mainly a C# Programmer?

Hello, Recently I've started to notice a lot of smirks and generally rude comments whenever I mention C#. Everyone I talk to either says learn Python or learn C++. Python is a nice language, I get it. But I don't find much use for it right now (for my use cases), and C++ I heard is a faster language (not sure). So my question is this...

Reference type and pointer in disassembly

Why reference types and pointers are same in compiled code?(You can see in third and fourth line). I tried to figure it out but apparently I could not achieve. If a reference type variable must be initialized at declaration and can not be changed so is there any need to do indirection as in pointers? int x = 10; mov dword ptr...

Template specialization of particular members?

Is it possible to specialize particular members of a template class? Something like: template <typename T,bool B> struct X { void Specialized(); }; template <typename T> void X<T,true>::Specialized() { ... } template <typename T> void X<T,false>::Specialized() { ... } Ofcourse, this code isn't valid. ...

Will splitting code into several .cpps decrease compilation time?

Hi, Suppose a have a fairly complex class I'm working on. Half the methods are done and tested, but I'm still devolping the other half. If I put the finished code in one cpp and the rest in another, will Visual Studio (or any other IDE for that matter) compile faster when I only change code that's in the "work-in-progress" cpp? Thanks!...

Linked list and copy constructor

I'm trying to write a basic, singly-linked list class in C++. I did it in my data structures class years back, but I can't remember the details. Should my Node class have a copy constructor? It has a Node* as a member variable, and as far as I know you're always supposed to write a copy constructor, destructor, and assignment operator f...

OpenGL / C++ - How do you fill an area surrounding a point on a mouse click?

Hi all, I've got the mouseclick handler correctly set up. I have a drawing with some shapes. Is there any way for me to fill the surrounding part of a point until it hits a polygon boundary. Something like Microsoft Paint's "fill" command. Thanks! ...

'variable name' cannot appear in a constant expression c++

Anyone have any clue what this error might actually mean? I'm tripping on a bit of code that can't seem to get around it. I've tried it with just h*2 instead of hprime, and just w*2 instead of wprime. Every time I get the same compiler (g++ compiler) error of : grid.cpp: In constructor ‘Grid::Grid(int, int)’: grid.cpp:34: error: ‘hpri...

Convert AES encrypted string to hex in C++

Hello, I have a char* string that I have encoded using AES encryption. This string contains a wide range of hex characters, not just those viewable by ASCII. I need to convert this string so I can send it through HTTP, which does not accept all of the characters generated by the encryption algorithm. What is the best way to convert t...

Why Size of Class with a member function is 1 byte..While member function is 4 bytes

Hi, I am not getting Why Size of Class with a member function is 1 byte..While member function is 4 bytes in the following example. class Test { public: Test11() { int m = 0; }; }; int main() { Test t1; int J = sizeof(t1); int K = sizeof(t1.Test11()); return 0; } Here J becomes 1 Byte an...

Base Copy constructor not called.

class Base { public: int i; Base() { cout<<"Base Constructor"<<endl; } Base (Base& b) { cout<<"Base Copy Constructor"<<endl; i = b.i; } ~Base() { cout<<"Base Destructor"<<endl; } void val() { cout<<"i:...

Problems with my Rabbit Hole templates?

Hi, there Today I've stepped into a problem I thought was so common I got myself wondering why only now I've noticed it. Imagine you have a class you want to handle using a boost::shared_ptr<>. This class has members that must forward shared_ptr<>s of itself to other methods; in other words, it has to create a shared_ptr<>s to the this ...

Getting appropriate hash index C++

I've tried everything. Even java's forumla: java.lang.String.hashCode(): s[0]*(31^(n-1)) + s[1]*(31^(n-2)) + ... + s[n-1] I've interpretted this as a sum: Although I am not quite sure what to do with the s[n-1]; int hashmap::hashstr( const char*const str ) { int result = 0; int i = 0; int j = 0; int k = 0; unsig...

How can I draw a "line" in a 2-D array (simulacrum for a screen)

Hello! I'm working on a project that's going to print out to a bitmap(more specifically a RAW, but that's not important to the question), but I'm working in a 2-D array in-program. I want to be able to draw a line from point (a,b) to point (x,y) for any arbitrary values of a,b,x, and y. I don't need anything fancy like anti-aliasing; a...

How can I use C++ code to interact with PHP?

I know C++ from college, vaguely. But I was reading somewhere that sometimes PHP is simply not fast enough and that real compiled code has to sometimes "Do the heavy lifting" what is the api in C++ to do this? Or whats the best way? I havent the slightest idea. What I do have is so experience writing old school C++, a linux box, a C+...

Function declarations and an unresolved external

I am looking after a huge old C program and converting it to C++ (which I'm new to). There are a great many complicated preprocessor hacks going on connected to the fact that the program must run on many different platforms in many different configurations. In one file (call it file1.c) I am calling functionA() and in another file (call ...

WinHTTP IWinHttpRequest iface - cookie handling - how to get cookies from response?

Hello I'm using WinHTTP IWinHttpRequest object. I do POST to a https domain specyfying a request body with credentials. The site is expected to return cookies in HTTP response. The code works in Wininet - but I don't know how in WinHTTP to get cookies from the HTTP response? Can anybody help? Dominik ...

Why check only certain values for errors? (C++?)

I recently started learning DirectX/Windows, and the book I'm learning from had the code d3d = Direct3DCreate9(D3D_SDK_VERSION); if(d3d == NULL) //catch error &c. My question is: What would cause an error in this line, that is different than what would cause an error in another line (say, for example, int num = 42)? ...

Memory leak tool for C++ under Windows

I need a recommendation of a free tool (even for a trial) for detecting memory leaks in C++ under Windows (Visual Studio 2005). I've looked in the net, but I would prefer a recommendation. ...

C# - Executables decompilable (can be reverse engineered)?

Is that right that C# can be reverse engineered? How is easy to do that? Can we say the C# is not enough good from safety aspect? And what about C++ compared with C# against decompiling? ...