c++

C++ "Variable not declared in this scope" - again

I guess this is a really simple question and, probably, one that has been answered several times over. However, I really do suck at C++ and have searched to no avail for a solution. I would really appreciate the help. Basically: #ifndef ANIMAL_H #define ANIMAL_H class Animal { public: void execute(); void setName(char*); Anima...

Help with understanding this algorithm

I would like to implement the Ramer–Douglas–Peucker_algorithm in C++. The pseudo code looks like this: function DouglasPeucker(PointList[], epsilon) //Find the point with the maximum distance dmax = 0 index = 0 for i = 2 to (length(PointList) - 1) d = OrthogonalDistance(PointList[i], Line(PointList[1], PointList[end])) if d > ...

Adding locks to the class by composition

I'm writing thread-safe class in C++. All of its public methods use locks (non-recursive spin locks). Private methods are lock-free. So, everything should be OK: user calls public method, it locks object and then does the work through private methods. But I got dead lock when a public method calls another public method. I've read that re...

How to obtain stacktrace when tracking memory leaks?

Hi, I've written a memory tracking system in c++ using Detours to patch the various memory allocation functions. When I receive a call to malloc in addition to the malloc I also store the stacktrace (so I can pin point the leak). The only reliable way to obtain an accurate stacktrace is to use StackWalk64 (I tried RtlCaptureStackBackTr...

Can a std::vector be ='d to another std::vector?

Say I have the following: std::vector<int> myints; and then I have a function that returns an int vector: std::vector<int> GiveNumbers() { std::vector<int> numbers; for(int i = 0; i < 50; ++i) { numbers.push_back(i); } return numbers; } could I then do: myints = GiveNumbers(); would doing this safely make it so that myints ...

Placing a byte at a very specific address on a hard disk, can it be done? (using c++ for example)

This might sound silly, but I'd like to know how to do the following. I've created a .txt file. The content of the .txt file is the word "hi" without the quotes. So the .txt file contains 2 characters. When opening the .txt file in a hex-editor one sees 2 hexadecimal pairs, namely "68" and "69": Offset 00000000 68 69 hi What I want t...

Does this pseudocode assume a zero based index?

I'm not sure if when they write 1 if this is the first or second element in the array: function DouglasPeucker(PointList[], epsilon) //Find the point with the maximum distance dmax = 0 index = 0 for i = 2 to (length(PointList) - 1) d = OrthogonalDistance(PointList[i], Line(PointList[1], PointList[end])) if d > dmax index = i...

multiple definitions question

This question is as a result of http://stackoverflow.com/questions/3495422/undefined-reference-question. When I try compiling this: #include "OriAudioCache.hpp" int main() { System *audioSystem(0); FMOD_RESULT result; result = System_Create(&audioSystem); FMOD_CHECK_STATE(result); OriAud...

How can I index a collection and allow each index's variable to have a custom setter?

So I have an object called Vertex which contains some parameters (let's call them sx, sy and i). sx, sy and i each have special setters: ie, Vertex looks something like class Vertex { public: float sx() { return sx; }; void setSx(float val) { val > 0 ? sx = val : sx = 0; }; float sy() {...

How to create a direct3d texture of a web page rendered by MSHTML in C++ ?

Hello all, I have integrated a web page inside my native C++ Application through MSHTML (Microsoft Rendering engine of IE). What I want to do now is to generate a LPDIRECT3DTEXTURE9 (Direct3d texture) of the displayed web page. Is it possible ? Do you know how to ? Thanks in advance for all your answers. ...

Embeddable Cross-Platform Web Browser?

I'm wondering if there is a Web Browser that I can embed in my Applications and that is cross-Platform (Windows, OS X, Linux)? I'm undecided about the programming language, but I guess I'll have to go the C++ route (in which case I'd likely choose Qt as a GUI Framework) unless something for .net/mono or Java exists? Doesn't need to be ...

Polymorphism and checking if an object has a certain member method.

I'm developing a GUI library with a friend and we faced the problem of how to determine whether a certain element should be clickable or not (Or movable, or etc.). We decided to just check if a function exists for a specific object, all gui elements are stored in a vector with pointers to the base class. So for example if I have class...

gslice definition in C++

I have some misunderstanding about the gslice function. Definition from MSDN states: gslice defines a subset of a valarray that consists of multiple slices of the valarray that each start at the same specified element. The ability to use arrays to define multiple slices is the only difference between gslice and slice::slice. The fir...

VC++ says "no overloaded function takes 7 arguments" I say YES IT DOES!

In my PDBComponent class's header file, I just created a new constructor for a grand total of two constructors: class PDBComponent { public: PDBComponent(string name,double min_current,double nom_current, double max_current, EPSCommands* command_ptr, double delay); PDBComponent(string name,double...

How to handle IHttpSecurity::OnSecurityProblem having a IWebBrowser2 object

Hello, I can't seem to understand how i give my implementation of the IHttpSecurity::OnSecurityProblem to my IWebBrowser2 object. I know that i need to implement a class something like this: class CServiceProvider : public IServiceProvider { public: CServiceProvider(); ~CServiceProvider(); // IUnknown ULONG STDMETHODCALLTYPE...

Printing lists with commas C++

I know how to do this in other languages, but not C++, which I am forced to use here. I have a Set of Strings that I'm printing to out in a list, and they need a comma between each one, but not a trailing comma. In java for instance, I would use a stringbuilder and just delete the comma off the end after I've built my string. How do I d...

Reverse a c-type string.

Here is my code: void reverseStr(char *str) { if (str == NULL) return; int i=0, j=strlen(str) -1; while(i<j) { char temp = str[j]; //i think this is the cause of the problem str[j] = str[i]; str[i] = temp; i++; j--; } } So here is where it is called: int main() { ...

[C++] operator << - how to detect last argument.

hi guys, I'm writting a log class in c++. This class is an singleton. I want to add logs in such a way: Log::GetInstance() << "Error: " << err_code << ", in class foo"; Ok, and inside a Log object, I want to save this whole line at the time when the last argument comes (", in class foo" in this example). How to detect the last one <...

How to define TypeConverter for enumeration drop down in Propertygrid in Visual C++ Winforms?

I would like to create a drop-down in a propertygrid in Visual C++ where I define text for each item of an enumeration. I cannot seem to find any help for this anywhere - all the help seems to be targeted to C# users and I am unable to convert to Visual C++. I believe I need to create a TypeConverter that converts my enumeration to Strin...

Substring search interview question

char* func( char* a, const char* b ) { while( *a ) { char *s = a, *t = b; while( (*s++ == *t++) && *s && *t ); if( *t == 0 ) return a; a++; } return 0; } The above code was written to search for the first instance of string "b" inside of string "a." Is there any probl...