Vectors and Windows Programming

This is a discussion on Vectors and Windows Programming within the Game Programming forums, part of the General Programming Boards category; Yeah, might want to create your own more useful point class then....

  1. #16
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Yeah, might want to create your own more useful point class then.

  2. #17
    Registered User
    Join Date
    Nov 2006
    Posts
    224

    Question

    Do you have any ideas of how to overcome this?

    IF I made my own POINT class then that could work, using a constructor as the guy before suggested?

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by strokebow View Post
    Nice thought. But,

    error C2661: 'tagPOINT::tagPOINT' : no overloaded function takes 2 arguments
    That's what I said... You could make a CPNT class, that is capable of returning a point (by default, perhaps). But it seems a bit unnecessary.

    I'd probably make a small utility function:
    Code:
    void AddPoint(vector<POINT>& v, int x, int y)
    {
        POINT p;
        p.x = x;
        p.y = y;
        v.push_back(p);
    }
    Then you can write something like
    Code:
        vector<POINT> square;
        AddPoint(square, 0, 0);
        AddPoint(square, 100, 0);
        AddPoint(square, 100, 100);
        AddPoint(square, 0, 100);
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    Nov 2006
    Posts
    224
    ahhh
    brilliant

  5. #20
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    You could write a class that uses Point and also overloads the common operators used on points such as addition, subtraction, equality, assignment, etc.

  6. #21
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    Or even this
    Code:
    class CustomPoint
    {
    public:
    	CustomPoint(int x, int y)
    	{
    		mPoint.x = x;
    		mPoint.y = y;
    	}
    	operator POINT&()
    	{
    		return mPoint;
    	}
    private:
    	POINT mPoint;	
    };
    
    void FunctionThatExpectsPoint(POINT pt)
    {
    	std::cout<<"x = "<<pt.x<<" y = "<<pt.y;
    }
    
    int main(void)
    {
    	std::vector<CustomPoint> myPoints;
    	myPoints.push_back(CustomPoint(30, 20));
    	myPoints.push_back(CustomPoint(10, 50));
    
    	FunctionThatExpectsPoint(myPoints[0]);
    
    	std::cin.get();
    
    	return 0;
    }
    Woop?

  7. #22
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Personally, I'd leave it as a C struct. Unless you want certain operations as Bubba mentioned.

    FYI, point is defined with "LONG" not "int" (note: not "long") . As per MSDN - http://msdn.microsoft.com/en-us/libr...19(VS.85).aspx

  8. #23
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,812
    Agreed.

    Just having some fun with overloaded operators.
    Woop?

  9. #24
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    I would derive from POINT and add specific features, since conversion operators can cause unexpected and unwanted implicit conversions.
    The brilliance of deriving from the original POINT is that you can then pass it to any function requiring a POINT* or POINT& and it will behave exactly the same.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #25
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    I would derive from POINT and add specific features, since conversion operators can cause unexpected and unwanted implicit conversions.
    The brilliance of deriving from the original POINT is that you can then pass it to any function requiring a POINT* or POINT& and it will behave exactly the same.
    Not entirely sure if that's correct:
    Code:
    class MYPOINT: PUBLIC POINT
    {
    public:
        int a;
        MYPOINT(LONG xx, LONG yy, int aa): x(xx), y(yy), a(aa)
        {
        }
    }
    
    ...
    void func()
    {
        MYPOINT *octagon = new MYPOINT[9];
    
       ... 
        Polygon(hdc, octagon, sizeof(octagon)/sizeof(octagon[0])); 
    ...
    }
    That will NOT work, because the pointer to the octagon contains 12 bytes per entry. Of course, nor will the CustomPoint method described above (at least not unless by chance).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #26
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,985
    Although now that you remind me, this opens a whole new can of worms, too.
    Perhaps the best course of action is a legacy get() function that returns a POINT.
    Then whether you derive from POINT or not is up to you.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #27
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    Although now that you remind me, this opens a whole new can of worms, too.
    Perhaps the best course of action is a legacy get() function that returns a POINT.
    Then whether you derive from POINT or not is up to you.
    Again, that will only work for individual POINT items - polygon takes an array [as a pointer], so you still need to have an array of them in some way.

    Using a function like I described WORKS - it is not the C++ way to do it, but unfortunately, I don't think that can be achieved at this point in time - because the GDI functionality that does the actual drawing in a Windows GUI application doesn't support OBJECTS as the input.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors, with vectors, windows programming... etc
    By bobbelPoP in forum C++ Programming
    Replies: 10
    Last Post: 07-27-2008, 04:07 AM
  2. Odd memory leaks
    By VirtualAce in forum C++ Programming
    Replies: 11
    Last Post: 05-25-2006, 01:56 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21