Thread: Overloading w/ and w/o static...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    752

    Overloading w/ and w/o static...

    *sigh* I'm stumped again. Right now, I'm basically trying to have it so that I have two versions of the same function.... this is kinda what I'm aiming for:
    Code:
    Wall A;
    Wall::shoot(&A);
    A.shoot();
    I am using MSVC++. Is there any way for me to get what I want done done?

    Code:
    C:\Documents and Settings\l1\Desktop\Windependent\Wall.cpp(36) : error C2663: 'shoot' : 2 overloads have no legal conversion for 'this' pointer
    Code:
    #ifndef Wall_H
    #define Wall_H
    
    #include "Types.h"
    
    class Wall {
    private:	
    	DoubleVector myNormal;
    	double dValue;
    	ColorCoefficient myColorCoeff;
    
    protected:
    	mutable DoubleVector hitPoint;
    
    public:
    	Wall ();
    	Wall (double normalX, double normalY, double normalZ, double posX, double posY, double posZ, int redDiffuse, int greenDiffuse, int blueDiffuse, int redReflect, int greenReflect, int blueReflect, int redAbsolute, int greenAbsolute, int blueAbsolute);
    
    	bool shoot (const Ray &myRay, double *t, double minT);
    	static bool shoot (void const * shootMe, const Ray& myRay, double * t, double minT);
    
    	static bool normal (void const * normalMe, Ray * result);
    	static void color (void const * colorMe, ColorCoefficient * result);
    }; // End class Wall
    
    
    
    #endif // Wall_H
    Code:
    bool Wall::shoot (const Ray& myRay, double * t, double minT) {
    	double top;
    	double bottom = -(myNormal.x * myRay.delta.x + myNormal.y * myRay.delta.y + myNormal.z * myRay.delta.z);
    	
    	if (bottom <= 0) return 0; // Don't hit if wall is facing wrong way.
    	
    	top = myNormal.x * myRay.initial.x + myNormal.y * myRay.initial.y + myNormal.z * myRay.initial.z + dValue;
    	
    	if ((*t = top/bottom) <= 0)
    		return 0;
    
    	if (*t > minT)
    		return 0;
    	
    	hitPoint.x = myRay.initial.x + *t * myRay.delta.x;
    	hitPoint.y = myRay.initial.y + *t * myRay.delta.y;
    	hitPoint.z = myRay.initial.z + *t * myRay.delta.z;
    
    	return 1;
    }
    
    bool Wall::shoot (void const * shootMe, const Ray& myRay, double * t, double minT) {
    	const Wall& shootMeWall = * (Wall *) shootMe;
    	return shootMeWall.shoot(myRay, t, minT); // This is line 36
    }
    Callou collei we'll code the way
    Of prime numbers and pings!

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Nevermind, figured out the problem. Was because I was using a const reference w/ a non-const member function.
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to create an n-dimensional array w/o pointers?
    By vikramkone in forum C++ Programming
    Replies: 1
    Last Post: 10-14-2006, 08:25 PM
  2. assignment makes int from pointer w/o cast
    By iain in forum C Programming
    Replies: 4
    Last Post: 11-25-2004, 11:03 AM
  3. Level order traversal w/o queue
    By curlious in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-16-2004, 07:54 AM
  4. Replies: 2
    Last Post: 10-09-2002, 11:22 PM
  5. Calling ISR w/o interrupt
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 11-02-2001, 05:29 PM