triumphost 120 Posting Whiz

Uhh What I posted does exactly that :S

//Access the vectors and then cout<< the result.

cout<<MyVec[0];    //Prints 3.2
cout<<MyVec[1];    //Prints -5.4
cout<<MyVec[2];    //Prints 5.6

anything other than those 3 numbers [0], [1], [2].. Will produce an error.

triumphost 120 Posting Whiz

I think this is what u meant?? Sorry if it's not and sorry for using double instead of float if it is correct.

#include <assert.h>
#include <iostream>

using namespace std;

class Vector3D
{
	private:
		double X, Y, Z;
		
	public:
		Vector3D() : X(0), Y(0), Z(0) {}
		Vector3D(double X_, double Y_, double Z_) : X(X_), Y(Y_), Z(Z_) {}
		~Vector3D() {}
		
		
		double& operator [](int Index)
		{
			assert(Index >= 0 && Index <= 2);
			
			if (Index = 0)
				return X;
			else if (Index = 1)
				return Y;
			else if (Index = 2)
				return Z;
		}
                
                //const overload here..

};

int main()
{
	Vector3D MyVec(3.2, -5.4, 5.6);

	cout<<MyVec[0];
        cout<<MyVec[1];
        cout<<MyVec[2];
	cin.get();
	return 0;
}
triumphost 120 Posting Whiz

Is it Dangerous to Derive from STD? Specifically std::string.

Why I'm asking?

I want to write a class that extends the functionality of std::string and a couple other std structs/classes.. So that when I do something like:

String M = "";
M.Explode(........) it'll do the functionality in my class below.

Thing is I'm reading that it's very dangerous (on google at least).. and that I should "NEVER DERIVE FROM STD!!!!" because something about the destructor or constructor being virtual sometimes?

For example:

class Strings  :  public std::string
{
    private:
        vector<string> &SplitWrapper(const string &s, char delim, vector<string> &elems)
        {
            stringstream ss(s);
            string item;
            while(getline(ss, item, delim))
            {
                elems.push_back(item);
            }
            return elems;
        }

    public:
        vector<string> Explode(const string &s, char delim)
        {
            vector<string> elems;
            return SplitWrapper(s, delim, elems);
        }

        string Implode(string Glue, string Pieces[])
        {
            int I, Len;
            string Result = "";

            Len = HIGH(Pieces);
            if (Len < 0)
                return Result;
            Result = Pieces[0];
            for (I = 1; I < Len; I++)
                Result += Glue + Pieces[I];
        }

        string Implode(const string &Glue, const vector<string> &Pieces)
        {
            string Str;
            int Len = Pieces.size();
            for(int I = 0; I < Len; I++)
            {
                Str += Pieces[I];
                if (I < (Len - 1))
                    Str += Glue;
            }
            return Str;
        }

        bool isUpper()
        {
            
        }
};
triumphost 120 Posting Whiz

An easy way to use variadic template functions is with direct recursion:

#include <iostream>

using namespace std;

void foo()
{
    // Base case for variadic recursion
}

template<typename T, typename... Args>
void foo(T first, const Args... remaining)
{
    // Use the first argument
    cout << first << endl;
    
    // Recursively pass on the remaining arguments
    foo(remaining...);
}

int main()
{
    cout.setf(ios::boolalpha); // To make bool args print right
    
    foo(1, "test", 3.14159, 'Q', true, 6);
}

Hey I figured it out.. I had to set compiler flags for codeblocks.. but for visual studio, it won't work.

THANX! Your the best :)


Edit:

Oops meant to PM that.

triumphost 120 Posting Whiz

Because when I do something like:

int main()
{  
   M Arr;
   Arr.Insert(MyTypes, MyTypes, MyTypes......... up to any amount);
}

it gives an error saying function only takes 1 argument. Too many arguments in function call.. initial value of reference to non-const must be an l-value..

now if I do:

template<typename T, typename... Args>
		M& Insert(const T& first, const Args&... args)
		{
			for (unsigned I = 0; I < Args; I++)
				P.push_back(Args[I]);
			return *this;
		}

It gives me errors about missing comma's before ... and missing comma before &.. etc.

triumphost 120 Posting Whiz

How can I do the following? I read up on Variable Arguments last time I asked this question (Mike pointed me in the right direction).. but it still does not let me define any number of them.. I Do not want to specify the first parameter and if I do, it has to be a custom type.

Class M
{
	private:
	  vector<MyTypes> P;
	  
	//Constructor..
	//Destructor..
	  
	M& Insert(...)//or M& Insert(MyTypes, ...)   //where ... can ONLY be "MyTypes"
	{
	   for (int I = 0; I < #ofArgs; I++)
		P.push_back(Args[I]);
		
	   return *this
	}
}

I looked at doing it via templates but how can I even do that when I'm trying to do it in a class and access it without having to put template<.....> in front of it every single time.

triumphost 120 Posting Whiz

But I already have what the Banfa posted.. it just keeps giving me some compiler error (OUT OF RANGE).. so that's why I assumed I was doing it wrong..

MyType& operator [](int I)
        {
			assert(I >= 0 && !MyType.empty());
            return P[I];
        }

		const MyType& operator [](int I) const
		{
			assert(I >= 0 && !MyType.empty());
            return P[I];
		}

and the Actual program that gives me the error:

#include <windows.h>
#include <iostream>
#include "Types.h"

using namespace std;

int main()
{
	ArrayOfTypes P;
        P[0] = MyType();       //Assertion error..
        cout<<P;

	cin.get();
	return 0;
}

So with that error, I removed the !MyType.isEmpty.. and I get subscript out of range.

triumphost 120 Posting Whiz

I'll get straight to the point as it's very difficult to do since I haven't found the answer on google or anywhere else.

Class ArrayOfTypes
{
	vector<MyType> P;

	&MyType operator [](int I) = (MyType& PT)
	{
	   if (P[I] != PT)
	   {
		  P[I] = PT;
	   }
	   return P[I];
	}
}

Anyone understand what I'm trying to do? I'm trying to overload both [] and = at the same time so that I can assign to a specific location in my vector P.

triumphost 120 Posting Whiz

After encryption and decryption, it's hard to read back.. what you do is that for each line, encode/decode using base64 as if u don't, sometimes the characters won't be read back exactly how they were..

Had this happen to me before.. so I just used base64 or hexadecimal for each char.. and it fixed it..

Dunno if that'll help u though.

triumphost 120 Posting Whiz

I have:

private: Void GoBtn_Click(Object^  sender, EventArgs^  e)
{				                                                                      ((WebBrowser)MultiTab->SelectedTab->Controls[0]).Navigate(SearchBar->Text);
}

But it keeps giving me an error at Controls[0] and telling me that no operator [] matches..

Control::Collection^ [int] <--- No clue what that line means..

Next it tells me that I cannot cast TabControl to (WebBrowser)

or if I do:

WebBrowser MultiTab = new WebBrowser; it tells me something about static references only..


With all that said, how am I supposed to make a new instance of a webbrowser dynamically and how do I access the browser on a specific tab?

triumphost 120 Posting Whiz

Is there any C++ .Net IDE's around? I mean visual studio is ok.. it just isn't as good as SharpDevelop which only does C#, VB and a few others. It doesn't do C++ that's why I'm looking for a C++ version of SharpDevelop.

Any Ideas?

SharpDevelop
http://www.icsharpcode.net/opensource/sd/

triumphost 120 Posting Whiz

I'm trying the templates but still don't get it:

//Does not work:
    template<typename... Values>
    void foo(const Values&... values)
    {

    }
//Works:
template <typename ...Args> class SomeStruct {
    void Foo(Args...);
};
triumphost 120 Posting Whiz

How can I get a variable amount of arguments in a function without providing how many arguments will be passed?

For example, when you use a VA List, the first parameter must be the amount of arguments passed.. I don't want that. I want to just start passing any amount of arguments to the function.

Is there a way to do this? I've heard that the boost library supports this.. Whether or not that is true, I don't know but I don't "want" to use boost. Though I may have to if the above statement is true and there is no other way.

So again, can I do this? And if not, why?

triumphost 120 Posting Whiz

Follow what I was told above, I still cannot compile.. And can someone explain what mike means by "It's dangerous"? Why is it dangerous?

I plan to translate this to C# as soon as I learn how to fix it and why everything in C# is static -____-

The changes and additions now look like:

class ANew
{
    private:
        vector<CustomType> ArrayOfTypes;
        int rows;

    public:
        ANew() {}
        ~ANew() {}

        CustomType& operator ()(int I)
        {
            return ArrayOfTypes[I];
        }

        CustomType& operator [](int I)
        {
            return ArrayOfTypes[I];
        }

        operator const vector<CustomType> () const
        {
            return ArrayOfTypes;
        }

        int operator == (const ANew &AN)
        {
            return (ArrayOfTypes == AN.ArrayOfTypes);
        }

        int operator != (const ANew &AN)
        {
            return !(ArrayOfTypes == AN.ArrayOfTypes);
        }

        ANew& operator = (const CustomType& CT)         //Add the CustomType to ArrayOfTypes. Ex: ArrayOfTypes AN = CustomType X
        {
            if (this[LEN(this)] != &CT)			//#define LEN(a) (sizeof(a)/sizeof(*a))
            {
                this.push_back(CT);
            }
            return *this;
        }

        ANew& operator = (const ANew& AN)
        {
            if (this != &AN)
            {
                this = AN;
            }
            return *this;
        }
};
triumphost 120 Posting Whiz

I have:

class ANew
{
    private:
        vector<CustomType> ArrayOfTypes;

    public:
        ANew() : ArrayOfTypes(0) {}
        ~ANew() {}

        ANew& operator ()(int I)
        {
            return ArrayOfTypes[I];
        }

        operator const ANew* () const
        {
            return ArrayOfTypes;
        }
};

But it gives me these errors:

C++\Types.h|12|error: invalid initialization of reference of type 'ANew&' from expression of type 'CustomType'|

C++\Types.h|17|error: cannot convert 'const std::vector<CustomType, std::allocator<CustomType> >' to 'const ANew*' in return|

I don't know if it's possible to overload those operators or if I'm doing it right.. Any help is appreciated.

triumphost 120 Posting Whiz

http://codepad.org/edEYoes9

Wow.. What in the world kinda sorcery is this?! Probably confused me even more now.. WHY?! Why does it print 0 for you and for me in console, it prints nothing? I have that exact code.. if I do cout<<hex<<'\0'; it will be blank whereas cout<<int<<'\0'; prints a value.. question is though.. Are they really all the same? That's odd.. why does converting to hex before my encryption work whereas just doing pure ascii key codes mess it up.

triumphost 120 Posting Whiz

Someone please tell me the difference between 0 and '\0' and NULL.

I thought I knew it! 0 and NULL is the same thing "Essentially".. '\0' is a null terminator for a string..

It's just sometimes when I convert a string to char array and do some encryption on it, I see TWO null terminating characters.. wth? The second one should never be there and should never get reached because the string terminates as it hits the first.. Thing is.. WHY does this second NULL Terminator appear out of NO where? Now here is where the problem lies in my mind.

I can convert all the chars in the chararray (INCLUDING the NULL Terminator) to ASCII codes and they all convert perfectly fine into the (Int) values.. Converts vice-verse into (char) as well.. So no problem there..

Now when doing the same with Hex.. It leaves out the NULL terminator. Aka char to hex to char.. When it hits the Hex part, it is 1 char less and thus the output chararray is also 1 char less.. (The original minus the Null terminator).

Now Why does ASCII have codes for NULL Terminating characters but Hex does not? Hex has the value 0.. should it not use that?

triumphost 120 Posting Whiz

Ok I think I have the hang of it but I'm not sure if my bitmaps/objects are getting freed :S Why? Because for loadfromfile I did this->Bmp =.. thats because bmp is a pointer to a bitmap no?

Yet when I do M.Freed and then M.Exists() it still says it exists :S

I wasn't sure if LoadFromFile should be void or HBitmap and return one..

//My tester..

#include "Bitmap.h"

using namespace std;

int main()
{
    Bitmap M;
    M.LoadBitmapFromFile("Untitled.bmp");
    int X = 0; int Y = 0;
    M.GetSize(X, Y);
    M.Free();
    cin.get();

    return 0;
}

//My class..

class Bitmap
{
    private:
        HBITMAP Bmp;
        HANDLE hFile;
        DWORD Written;
        BITMAPFILEHEADER bFileHeader;
        BITMAPINFOHEADER bInfoHeader;
        unsigned char* Image;

    public:
        Bitmap() : Bmp(0) {}
        Bitmap(HBITMAP hBmp) : Bmp(hBmp) {}
        Bitmap(Bitmap &Tbmp) : Bmp(Tbmp.Release()) {}
        ~Bitmap() {Free();}
        void Free() {if(Bmp){DeleteObject(Bmp);}}

        operator HBITMAP() {return Bmp;}
        bool Exists()
        {
            if (!this->Bmp)         //BMP is a handle pointing to a bitmap.
                return false;
            return true;
        }

        HBITMAP GetHandle()
        {
            return this->Bmp;
        }

        void operator = (Bitmap &Tbmp)
        {
            if (Tbmp.Bmp != Bmp)
            {
                Free();
                Bmp = Tbmp.Release();
            }
        }

/*        Bitmap& operator = (Bitmap& Tbmp)
        {
            if (this != &Tbmp)
            {
                Free();
                Bmp = Tbmp;
            }
            return *this;
        }
*/

        void LoadBitmapFromFile(const char* FilePath)
        {
            hFile = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
            if (hFile == 0)
            {
                std::cout<<"Error Bitmap Does Not Exist";
                //throw "Error";
                return;
            }

            ReadFile(hFile, &bFileHeader, sizeof(bFileHeader), &Written, 0);
            ReadFile(hFile, &bInfoHeader, sizeof(bInfoHeader), &Written, 0);

            if (bInfoHeader.biBitCount < 24)
            {
                CloseHandle(hFile);
                MessageBox(NULL, "The Image …
triumphost 120 Posting Whiz

Hmmm but I want to learn to handle bitmaps myself :S I'm writing a header file for bitmaps.. It's to be used with Bitmap Finding functions with screenshots and images and stuff.. Sorta like image recognition.

I figured out how to write bitmaps to a file and how to get bitmaps from a device context but for the life of me cannot figure out if it's a 24 bit/32bit/32a bit bmp.. and how to handle anything other than 24 bit.. I can work with 24 bit but don't see any tuts on the other two types or how to determine which is which.

triumphost 120 Posting Whiz

I read a LOT of tutorials on bitmaps. I learned that RGBQuad is for 32 bit bitmaps and RGBTripple is for 24 bit bitmaps..

I'm planning on getting pixel information from a bitmap that can be of 3 types. 24bit, 32bit, 32bit with alpha (Transparent).

Thing is, I don't know how to determine what types of bitmaps I'm loading (24, 32, 32a).
I have to be able to draw these to a Window/DC.


This is what I have so far.. Can anyone point me in the right direction? Can I use LoadImage?

#include <windows.h>
#include <iostream>

using namespace std;


                            /** 24-Bit Bitmaps **/
class TBitmap
{
    private:
        HANDLE hFile;
        DWORD Written;
        BITMAPFILEHEADER bFileHeader;
        BITMAPINFOHEADER bInfoHeader;
        RGBTRIPLE *Image;

    public:
        void LoadBitmapFromFile(const char* FilePath)
        {
                            /** Open File **/
            hFile = CreateFile(FilePath, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);

                            /** Read Header **/

            ReadFile(hFile,&bFileHeader,sizeof(bFileHeader),&Written,NULL);
            ReadFile(hFile,&bInfoHeader,sizeof(bInfoHeader),&Written,NULL);

                            /** Read Image **/

            int imagesize = bInfoHeader.biWidth * bInfoHeader.biHeight;             //Math to Allocate memory for the inamge.
            Image = new RGBTRIPLE[imagesize];                                       //Create a new image. Array.
            ReadFile(hFile, Image, imagesize * sizeof(RGBTRIPLE), &Written, 0);     //Reads images.
            CloseHandle(hFile);                                                     //Close File Handle.
        }

                                    /** GetPixel Location **/

        RGBTRIPLE GetPixel(int X, int Y)
        {
            return Image[(bInfoHeader.biHeight - 1 - Y) * bInfoHeader.biWidth + X];  //BMP is upside-down due to the way screen co-ordinates work.
        }

                                    /** Set Pixel Colour **/

        RGBTRIPLE SetPixel(int X, int Y, RGBTRIPLE Colour)
        {
            Image[(bInfoHeader.biHeight - 1 - Y) * bInfoHeader.biWidth + X] = Colour;
        }
};


int main()
{
    TBitmap …
triumphost 120 Posting Whiz

I added that operator [].. Still the Length returns 1 all the time :S I tried the aLen and it still kept returning 1 so I removed it since its the same as it was before. Here is my actual .CPP file if your want to see.

#include <math.h>
#include <vector>
#include <assert.h>
#include <sstream>
#include <stdarg.h>
#include <iostream>

using namespace std;


/** Definitions **/
#define LEN(a) (sizeof(a)/sizeof(*a))
#define HIGH(a) (sizeof(a)/sizeof(*a) - 1)

#define Repeat do{
#define Until(condition) }while(!(condition));

#define writeln(Output) (cout<<Output<<"\n");

/** Types **/

class Point
{
    private:
        int X, Y;

    public:
        Point() : X(0), Y(0) {}                            //Default constructor.
        Point(int X_, int Y_) : X(X_), Y(Y_) {};           //Alternate constructor.
        ~Point(){};                                        //Destructor.

        int operator == (const Point &PT) const            //Are the points Equal?
        {
            return ((X == PT.X) && (Y == PT.Y));
        }

        int operator != (const Point &PT) const            //Are the points Not equal?
        {
            return ((X != PT.X) && (Y != PT.Y));
        }

        Point& operator = (const Point& PT)
        {
            if (this != &PT)
            {
                X = PT.X;
                Y = PT.Y;
            }
            return *this;
        }

        Point operator += (Point PT)
        {
            X += PT.X;
            Y += PT.Y;
            return *this;
        }

        Point operator -= (Point PT)
        {
            X -= PT.X;
            Y -= PT.Y;
            return *this;
        }

        friend ostream& operator << (ostream& Str, const Point &PT)      //For use with Writeln & cout.
        {
            Str<<"("<<PT.X<<", "<<PT.Y<<")";
            return Str;
        }

        friend inline Point operator + (Point P1, Point P2)           //Add two points.
        {
            return Point(P1.X + P2.X, P1.Y + P2.Y);
        } …
triumphost 120 Posting Whiz

Doesn't work.. I get the same error "Invalid use of non-static member..
I don't think it's possible.. maybe instead of doing XY* I can do a vector?

Edit: Tried the vector and failed..

triumphost 120 Posting Whiz

But how can I keep track of the array length without having to pass an int in my actual .cpp file?

I've tried:

struct JK
{
  private:
     XY* Me;
     int ALen;
  public:
     JK(){ALen = sizeof(Me)/sizeof(ME[0]);}

  friend ostream& operator << (ostream& Str, const JK &Meh)
  {
     for (int I = 0; I < ALen; I++)         //Put ALen here..
     {
        Str<<" "<<Meh[I]<<" ";
     }
     return Str;
  }
}

But it still gives me problems..

triumphost 120 Posting Whiz

Sorry for using Inception in the title but it's the only way I think I can describe it..

Take this for example:

Definition.H

struct XY
{
  string info;
  string name;
  string tag;
  string attrib;
}; //is it better to create an object here inorder to make the array?

struct JK
{
  XY* Me;
  friend ostream& operator << (ostream& Str, const JK &Meh)
  {
     for (int I = 0; I < sizeof(Meh)/sizeof(Meh[0]); I++)
     {
        Str<<" "<<Meh[I]<<" ";
     }
     return Str;
  }
}

Struct JK creates an array of Struct XY.. Now when I try to print out the contents of the Array.. it returns 1 for the size every single time! Why? Is my math wrong? Am I doing something wrong? Why is sizeof(Meh)/sizeof(Meh[0]).. 1? I just want it to print all the contents of the array.

In my program I have:

JK P[10].. Shouldn't the size be 10? or the amount of elements?
In my program, I can access each element of the array and print them like:
cout<< *P[0]<<*P[1].. etc..

But I cannot do that in the above code in the Definition.H.

triumphost 120 Posting Whiz

I don't exactly know what you mean by "Expanded". That can be dynamically or allocated previously.

When I step through, it prints:

PointArray P Size = 10    //This is correct because I did PointArray P[10];
P[0] = (1, 2);            //This is correct because I assigned it a point;

So yes it holds the values but I cannot allocate a dynamic array of Points.

If you'd like to run/test/read any of the entire source, see below:

Test Program:

#include "Types.h"
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    Point P(1, 2);
    Point Q(3, 4);

    PointArray Z[10];
    writeln(LEN(Z));

    Z[0] = P;
    Z[1] = Q;

    writeln(*Z[0]);     //NOT sure why I have to use *Z to deference AGAIN?!
    writeln(*Z[1]);

    cin.get();
}

Types.h

#ifndef TYPES_H_INCLUDED
#define TYPES_H_INCLUDED
#include <math.h>
#include <vector>
#include <assert.h>
#include <sstream>

using namespace std;


/** Definitions **/
#define LEN(a) (sizeof(a)/sizeof(*a))
#define HIGH(a) (sizeof(a)/sizeof(*a) - 1)

#define Repeat do{
#define Until(condition) }while(!(condition));

#define writeln(Output) (cout<<Output<<"\n");

/** Types **/

struct Box;
struct Point
{
    int X, Y;
    Point() {X = Y = 0;};                              //Default constructor.
    Point(int X_, int Y_) : X(X_), Y(Y_) {};           //Alternate constructor.
    ~Point(){};                                        //Destructor.

    int operator == (const Point &PT) const            //Are the points Equal?
    {
        return ((X == PT.X) && (Y == PT.Y));
    }

    int operator != (const Point &PT) const            //Are the points Not equal?
    {
        return ((X != PT.X) && (Y != PT.Y));
    }

    Point& operator = (const Point& PT)
    {
        if (this != &PT)
        {
            X = PT.X; …
triumphost 120 Posting Whiz

It should? I want it to be dynamic like a vector so that it pushes the next point into it..

triumphost 120 Posting Whiz

The below code is what I have.. It's a custom type I made called Points that stores co-ordinates on the screen.. The problem is in the PointsArray Struct. When I declare one like so:

PointArray P;
    Point A(10, 5);

    for (int I = 0; I < 5; I++)
    {
        P[I] = A;
        cout<<P[I].X;
    }

It terminates the process with a status of 3.. The Points Array struct is supposed to make a vector/dynamic array of Points. What causes this error 3?

struct Point
{
    int X, Y;
    Point() {X = Y = 0;};                              //Default constructor.
    Point(int X_, int Y_) : X(X_), Y(Y_) {};           //Alternate constructor.
    ~Point(){};                                        //Destructor.

    int operator == (const Point &PT) const            //Are the points Equal?
    {
        return ((X == PT.X) && (Y == PT.Y));
    }

    int operator != (const Point &PT) const            //Are the points Not equal?
    {
        return ((X != PT.X) && (Y != PT.Y));
    }

    Point& operator = (const Point& PT)
    {
        if (this != &PT)
        {
            X = PT.X;
            Y = PT.Y;
        }
        return *this;
    }

    Point operator += (Point PT)
    {
        X += PT.X;
        Y += PT.Y;
        return *this;
    }

    Point operator -= (Point PT)
    {
        X -= PT.X;
        Y -= PT.Y;
        return *this;
    }

    Point MidPointBox (const Box &B);

    friend inline Point operator + (Point P1, Point P2)           //Add two points.
    {
        return Point(P1.X + P2.X, P1.Y + P2.Y);
    }

    friend inline Point operator - (Point P1, Point P2)           //Subtract two points.
    {
        return Point(P1.X - P2.X, P1.Y - P2.Y); …
triumphost 120 Posting Whiz

How can I forward declare a struct/custom type in my include? I'm trying to write an include but it keeps telling me incomplete type or type not declared..


I do not have a .CPP to go with it.. I wrote everything in here as I have never written an include before. The problem is at line 57, MidPointBox. Also Am I supposed to use templates?

Types.h

#ifndef TYPES_H_INCLUDED
#define TYPES_H_INCLUDED
#include <math.h>


/** Definitions **/
#define LEN(a) (sizeof(a)/sizeof(*a))
#define HIGH(a) (sizeof(a)/sizeof(*a) - 1)

#define Repeat do{
#define Until(condition) }while(!(condition));


/** Types **/

struct Box;

struct Point
{
    int X, Y;
    Point() {X = Y = 0;};                              //Default constructor.
    Point(int X_, int Y_) : X(X_), Y(Y_) {};           //Alternate constructor.
    ~Point(){};                                        //Destructor.

    int operator == (const Point &PT) const            //Are the points Equal?
    {
        return ((X == PT.X) && (Y == PT.Y));
    }

    int operator != (const Point &PT) const            //Are the points Not equal?
    {
        return ((X != PT.X) && (Y != PT.Y));
    }

    Point& operator = (const Point& PT)
    {
        if (this != &PT)
        {
            X = PT.X;
            Y = PT.Y;
        }
        return *this;
    }

    Point operator += (Point PT)
    {
        X += PT.X;
        Y += PT.Y;
        return *this;
    }

    Point operator -= (Point PT)
    {
        X -= PT.X;
        Y -= PT.Y;
        return *this;
    }

    Point MidPointBox (Box B)
    {
        int MX = ((B.X1 + B.Y1)/2);
        int MY = ((B.X2 + B.Y2)/2);

        return Point(MX, MY);
    }

    friend inline Point operator+(Point P1, Point P2)           //Add two …
triumphost 120 Posting Whiz

Well you posted no code.. so how are we supposed to know?

triumphost 120 Posting Whiz

Ok.. I went to the drawing board and I tried! I just can't understand what you guys mean.. I don't want to have to do it like that..

I want to sorta do it like the below.. and I want to know if I need a default constructor + a destructor.. Mine doesn't work.

#include <iostream>
#include <vector>

using namespace std;

struct Point
{
    int X, Y;
    Point() {X = 0; Y = 0;};  //Default constructor?
    Point(int X_, int Y_) : X(X_), Y(Y_) {}
    //~Point() {delete Point}   Why doesn't it work?
};

struct Box
{
    int X1, Y1, X2, Y2;
    Box(int X1_, int Y1_, int X2_, int Y2_) : X1(X1_), Y1(Y1_), X2(X2_), Y2(Y2_) {}
};

struct PointArray
{
    vector<Point>P;
    PointArray[vector<Point>P_] : P[P_] {};
};

int main()
{
    Point P(2, 3);
    Box A(2, 4, 1, 1);
    PointArray PA;
    PA[10].X = 1;
    PA[10].Y = 2;
    PA[2] = [Point(10, 1), Point(3, 2), Point(0, 4)];
}
triumphost 120 Posting Whiz

The first answer was what I wanted :) But it was only answering one question..

It works wonders for calling Points like how he did it but I want to define a type called PointArray which creates an array of Points and you can set the size of it later on somewhere in the code. It's my first time working with structs and classes so I have not a single clue what I'm doing.. I read tutorials on CPlusPlus.com but it doesn't tell me how to create an array of a custom type and be able to reference it like the first guy that commented. I'm looking into constructors now that he's mentioned it.
I still mix up when to use -> vs . and ::

//So like:

struct PointArray
{
  vector<Point>P;   //Or dynamic array of Points.
  P(int X_, Y_) : X(X_), Y(Y_) {}   //<--- didn't know how to define it there?
}

//So I can use it like:

int main()
{
  PointArray P;
  Memset(Point, 5, size*sizeof(Point));

  P = [point(1, 2), point(3, 4)];
  P[0] = Point(0, 0);
  P[1].X = 3;
  P[1].Y = 4; 
}
triumphost 120 Posting Whiz

In pascal, you can have something like the following:

type
    TPoint = record
     X, Y: Integer;
  end;
  TPointArray = array of TPoint;
  T2DPointArray = array of TPointArray;

In C++ I tried to replicate this and failed miserably.

struct Point
{
   X: Integer;
   Y: Integer;
};

struct PointArray
{
   //Array of Points? :S
   //Don't know if to use vectors or not or even how to do this..

   vector<Point>X;
}

And I want to be able to use it like so:

int main()
{
   Point P;
   P(X, Y);
}

How can I do this?

triumphost 120 Posting Whiz

How can I detect 3D Images? These images rotate in every direction in a game and I want to be able to detect them and click the right ones.

Where would I start?

I was thinking just loading a lot of bitmaps and somehow making a 3D image of it and finding each one frame by frame? Ahh I'm so confused!

Help? I just need a point in the right direction or an Idea or something..

triumphost 120 Posting Whiz

Only thing I can think of is the includes that you have..

You need <vector>, <iostream>

triumphost 120 Posting Whiz

I believe this happens due to a typo; Theading vs. Threading .

THANK YOU!!!! I cannot believe I didn't notice that.. man u have good eyes. I'll mark the thread solved. Rep++

Completed my DLL :D

#include <windows.h>
#include <iostream>


//DLL Function: void DLL_EXPORT Theading(HANDLE hThread, DWORD ThreadID, void* FunctionToPass);

typedef void (*CThread)(HANDLE hTThread, DWORD TThreadID, void* FuncToPass);

void FunctionToPassX()
{
    std::cout<<"meh";
}

int main()
{
    HINSTANCE h = LoadLibrary(TEXT("Threading.dll"));
    if (h)
    {
        std::cout<<"DLL Loaded.\n";
        CThread TThread;
        TThread = (CThread) GetProcAddress(h, "Threading");

        if (NULL != TThread)
        {
            std::cout<<"Function Found.";
            HANDLE HThread;
            DWORD TThreadID = 1;
            TThread(HThread, TThreadID, (void*) FunctionToPassX);
        }
        FreeLibrary(h);
    }

	std::cin.get();
    return 0;

}
triumphost 120 Posting Whiz

Why does it load my DLL but the pointer to the Proc returns 0? It loads the DLL and says "DLL Loaded" but it just won't say "Function Found." Help me please :)?

#include <windows.h>
#include <iostream>


//DLL Function: void DLL_EXPORT Theading(HANDLE hThread, DWORD ThreadID, void* FunctionToPass);

typedef void (*CThread)(HANDLE hTThread, DWORD TThreadID, void* FuncToPass);

void FunctionToPassX()
{
    std::cout<<"meh";
}

int main()
{
    HINSTANCE h = LoadLibrary(TEXT("Threading.dll"));
    if (h)
    {
        std::cout<<"DLL Loaded";
        CThread* TThread = (CThread*)(GetProcAddress(h, "Threading"));

        if (NULL != TThread)
        {
            std::cout<<"Function Found";
        }
        FreeLibrary(h);
    }

	std::cin.get();
    return 0;

}
triumphost 120 Posting Whiz

Ok I've done the following yet I cannot get the thread to run the function :S
Any ideas?

#include<windows.h>
#include <iostream>


void FunctionToPass()
{
    //This function can be any type.. not just void..
    std::cout<<"meh";
}

DWORD WINAPI ThreadProc(LPVOID lpParameter)
{
    //Run the function! ={
    void* parameter = (void*)lpParameter;
    parameter;
}


int main()
{
    DWORD ThreadID = 1;
    HANDLE hThread = CreateThread(NULL, 0, ThreadProc, (void*)FunctionToPass, 0, &ThreadID);
    std::cin.get();
}
triumphost 120 Posting Whiz

Hey all, I'm trying to make a DLL that can be used in Pascal to enable multi-threading.

I've decided I want to export Threads in C++ to a DLL. Before I make DLL's I usually write the program first to test everything then I convert it to a DLL.

#include<windows.h>
#include<stdio.h>
#include<conio.h>
#include <iostream>


DWORD Thread(LPVOID lpParameter)
{

}

void FunctionToPass()
{
    //This function can be any type.. not just void.. and can have any amount of parameters.
}


int main()
{
    DWORD ThreadID = 1;
    HANDLE hThread = CreateThread(0, 0, Thread(*FunctionToPass()), 0, 0, &ThreadID);
}

The above does not do what I want it to do. I want it to be able to take in functions, and have the thread run them. It's actually my first time learning threads so I have no clue what I'm doing wrong. Codeblocks keeps telling me void not ignored as it ought to be.

Oh and would I actually be able to export this to a DLL? So that in any program, I can just create threads that take in functions?

triumphost 120 Posting Whiz

How do interpreters do it?

I've seen bots for games that encrypt files then decrypt them at runtime and run what's in them..

Well How? How can I do this in C++? I plan to do this in another language but I decided to ask in C++ section because this is my strongest language and I'd understand anything posted better..

Example:

int funct()
{
	fsdh9hsdg				//Encrypted code.. Decrypted to: SetMousePos(X, Y);
	gdsgdsghshs				//encrypted code.. aka.. If else statement..
	hshsdhfshfshs
	hshsfhfhdfhdfhd
}

int Foo()
{
	decryptfunction('funct');
	//Run the decrypted function.. aka funct; so the mouse should move to X, Y?
}
triumphost 120 Posting Whiz

Ahh thank you guys.. this is actually a project that I assumed could take me at least a year or so.

I'll definitely look into what you guys have said. It's kinda both lol. I actually want to parse an existing language aka C++.. I used javascript as an example because it's the only example I could have thought of since I have never came across a c++ bot that parses a language.

I just spent the last 24 hours reading stack overflow, daniweb, etc, etc on parsers, lexers, etc to see how compilers do it.. I guess in short you can say I'm attempting to write an interpreter for c++?

I'm willing to put in the work though. If I have more questions, I'll be sure to check back and ask but thanks for now guys :D

triumphost 120 Posting Whiz

I have an idea for a program but I don't know if its possible.

I want to write a program that can read commands from a file.. For example, I've seen bots that can parse and read javascript for games and execute whatever is in the .java file..

How can I do this in c++ I want to read commands from a file and execute them.. Example:

Read MoveMouse(X, Y);... the client would SetCursorPos(X, Y);.

Possible or no?

triumphost 120 Posting Whiz

Hey all, I'm a c++ programmer and I'm REALLY new to pascal. I want to translate some of my programs into pascal just for the experience. The thing is, this Lazarus compiler is soooo confusing! All the windows are split apart.. How can I join them?

Next is how can I install/compile CurlPas.. I've tried a million times.. it's been 4 hrs and I've searched all over google. It keeps giving me this error LResources not found in unit1 used by lazcurl or something like that.. Its this LResources Error.. I've looked literally everywhere for it and don't know what else to do.

I tried using synapse instead but with no luck as the compiler cannot find the unit JPEG or BMP :S

Help?

triumphost 120 Posting Whiz

My problem is at line 54 and line 124.. Not sure how to fix it at all.. I basically just want to store all the values of NameIdx to the vector and print the values of the vector. But instead if shows random/AltKeyCode characters and crashes. I know its probably because the vector has no value at that address but I don't know why because I assigned it one with .push_back.

#define _WIN32_WINNT 0x0601
#define BUFSIZE MAX_PATH
#include <windows.h>
#include <cstdio>
#include <iostream>
#include <WinBase.h>
#include <vector>

#define ARRAYSIZE(a) ((sizeof(a) / sizeof(*(a))) / static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))


using namespace std;

vector<string> DevicePath;

void DisplayVolumePaths(char* VolumeName, vector <string> &DevicePath)
{
    DWORD  CharCount = MAX_PATH + 1;
    char* Names     = NULL;
    char* NameIdx   = NULL;
    BOOL   Success   = FALSE;

    while(1)
    {
        Names = (char*) new BYTE [CharCount * sizeof(CHAR)];

        if (!Names)
        {
            return;
        }

        //  Obtain all of the paths for this volume.
        Success = GetVolumePathNamesForVolumeName(VolumeName, Names, CharCount, &CharCount);
        if(Success)
        {
            break;
        }

        if (GetLastError() != ERROR_MORE_DATA)
        {
            break;
        }

        //  Try again with the new suggested size.
        delete [] Names;
        Names = NULL;
    }

    if (Success)
    {
        //  Display the various paths.
        for (NameIdx = Names; NameIdx[0] != '\0'; NameIdx += strlen(NameIdx) + 1)
        {
            DevicePath.push_back(NameIdx);
        }
    }

    if (Names != NULL)
    {
        delete [] Names;
        Names = NULL;
    }

    return;
}

int main()
{
    DWORD  CharCount            = 0;
    char  DeviceName[MAX_PATH] = "";
    DWORD  Error                = ERROR_SUCCESS;
    HANDLE FindHandle           = INVALID_HANDLE_VALUE;
    BOOL   Found                = FALSE;
    size_t Index                = 0;
    BOOL   Success …
triumphost 120 Posting Whiz

I have a page that has a hidden button at the top. When a link is clicked, the button shows. I want to write javascript so that if the button is showing, add a breakline below it and if it is not showing, do nothing. My attempt & fail is below. Can someone shed some light?

<input type="button" id="listframes" value="Button" />		

<script type="text/javascript">
	//If the button is showing, then break line below it.. else do nothing
	var ButtonID = document.getElementById('listframes');

	if(ButtonID.style.display == 'block')
	{
		 document.writeln('<br /> \r\n');
	}
</script>

		
<iframe id="external_frame" name="ExternalFrame" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0"></iframe>
#listframes {
    display: none;
}
triumphost 120 Posting Whiz

That would be cross-browser scripting (XSS - one page's JavaScript manipulating a site from another source) and it should not be allowed, for very good security reasons.

Back up, rethink and redesign.

And, sorry, I know you didn't want to hear this.

It indeed is NOT manipulating another site's..

My site has an iframe with a page loaded in it.
Upon button click, resize MY site's body + My Iframe's width.

I have solved it anyway and it works but thanks for at least replying.

My solution:

function WindowSize()
{
	WinWidth = 0, WinHeight = 0;	//Initialize variables with a value of 0;
	if(typeof(parent.window.innerWidth) == 'number')	//Well I need the parent width of the iFrame aka browser width. Width is a number, not undefined..
	{
			//FireFox/Opera..
		WinWidth = parent.window.innerWidth;
		WinHeight = parent.window.innerHeight;
	}
	else if(parent.document.documentElement && (parent.document.documentElement.clientWidth || parent.document.documentElement.clientHeight))
	{
		//IE 6+
		WinWidth = parent.document.documentElement.clientWidth;
		WinHeight = parent.document.documentElement.clientHeight;
	}
	return WinWidth;
}

function BodyResize(ID)
{
	var IDTag = parent.document.getElementById(ID);
	
	if(IDTag.clientWidth == '1024')
		IDTag.style.width = (WindowSize() + 'px');
	else
		IDTag.style.width = '1024px';
}
triumphost 120 Posting Whiz

I have an iframe that loads a page inside it.. when a link is clicked on the page in the iframe, resize the body of the parent aka the document that has the iframe's body..


Example:

Body         <------------------------
   Iframe                            |
       Page                          |
         Link... Upon Click, resize --

How do I do the above? I tried Parent.document.body.style.width = "200px". and it didn't work. Not sure what to do. Please Help!

function Parentresize(id)
{
    var newheight = 2000;
    var newwidth = 2000;
    parent.document.getElementById(id).height= (newheight) + "px";
    parent.document.getElementById(id).width= (newwidth) + "px";
}
triumphost 120 Posting Whiz

Can someone explain why my function is not working? Description: ToggleFrame(TagID, FrameID).. Given those two, get the two elements.. If the iframe is showing, hide the tagID element.. if the tagID element is showing, hide the iframe..

My attempt & failure:

function ToggleFrame(ID, FrameID){			//Given the tag, show/hide it..
	var IDTag = document.getElementById(ID);
	var FTag = document.getElementById(FrameID);
	
	if(FTag.style.display == 'block')
	{
		IDTag.style.display = 'none';
	}
	else if(IDTag.style.display == 'block')
		FTag.style.display = 'none';
}
triumphost 120 Posting Whiz

Can you guys help me write a to match this? It should find 3 <td></td> 's in there..

Thing is they aren't separated by any spaces or anything.. so I'm not sure how to get them..

But I used <td(.*)</td>.. and it finds one match.. Any Ideas?

<td class="wsod_change" nowrap="nowrap"><span stream="arrow_599362" streamFeed="SunGard"><img src="http://i.cdn.turner.com/money/.element/img/3.0/data/arrowDown.gif" align="absmiddle" /></span>&nbsp;<span stream="change_599362" streamFeed="SunGard"><span class="negData">-74.70</span></span><span class="wsod_grey">&nbsp;/&nbsp;</span><span stream="changePct_599362" streamFeed="SunGard"><span class="negData">-0.61%</span></span><div class="wsod_quoteLabel wsod_quoteLabelChange">Today&rsquo;s Change</div></td><td class="wsod_52week" nowrap="nowrap"><div class="wsod_quoteRanger clearfix"><div title="10/04/2011" class="val lo">10,404</div><div class="wsod_quoteRangerMeter"><span class="wsod_qRangeInidicator" style="left:53px;">Today</span><span class="wsod_qRangeBarOuter"><span class="wsod_qRangeBarInner">|||</span></span><span class="wsod_quoteLabel52WkChg">52-Week Range</span></div><div title="05/02/2011" class="val hi">12,876</div></div></td><td class="wsod_ytd" nowrap="nowrap" ytdVal="4.331414958829656"><span class="posData">+4.33%</span><div class="wsod_quoteLabel wsod_quoteLabelYTD">Year-to-Date</div></td>
triumphost 120 Posting Whiz

Compiler Search Directories:
C:\Program Files (x86)\curl\include

Linker Search Directories:
C:\Program Files (x86)\curl\lib

Compiler Defines:

CURL_STATICLIB

Link Libraries:
curl
rtmp
idn
ssl
ssh2
crypto
z
ws2_32
wldap32
winmm
gdi32


Linker Options:
-static


Now compile your program.. It will not give errors.

triumphost 120 Posting Whiz

Trying to re-write a php function to C++ using boost.. I have NOT seen code for this anywhere on the net. I thought it was useful and I need it for C++ but I need help..

definition of the function in c++

void preg(string pattern, string subject, string &matches, int flags, int offset)       //Matches is a 2D array or map or 2d vector..
{

}

Function I want to re-write to C++..
http://php.net/manual/en/function.preg-match-all.php


Attempt (takes in a string, matches it to an expression, returns the match:

string ID;           //Match to be returned.
string Source;              //Source of Data to match against..
boost::regex expression("(.*)");     //A patter to match..



void preg_match_all(string Source, boost::regex &expression, string &ID)
{
       try
       {
           std::string::const_iterator start, end;
           start = Source.begin();
           end = Source.end();
           boost::smatch what;
           boost::match_flag_type flags = boost::match_default;

//Match against the data.. if a match is found, return it to ID..

           while(boost::regex_search(start, end, what, expression, flags))
           {
                //Destination = boost::regex_replace(Source, expression, "");
                ID = what[0];
                start = what[0].second;
           }
       }
       catch(exception &e)
       {
           cout<<"Exception Caught.. Function: preg_match_all.\n\n";
       }

    return;
}

Problem.. I want it to return an array of every match it finds.. At the moment it returns one match..

Example Data:

<td vsgsgs> whatever else here</td><td>fsgsgs</td><td aifngn;aga></td>

It will return that whole thing into the string ID. I want it to return:

array[0] = <td vsgsgs> whatever else here</td>
array[1] = <td>fsgsgs</td>
array[2] = <td aifngn;aga></td>