Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 8th, 2006, 10:24 PM   #21
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
Quote:
Originally Posted by aznballerlee View Post
Similarly, if we used pointers for the Span parameters, would this apply?

double getOverlap (Span *span1, Span *span2)
double getOverlap (Span *span1, Span *span2)
{
    int m_high, m_low;
    if (this -> low() > this -> low())
        low = this -> low();
    else
    {   
        low = this -> low();
    }

    if (this -> high() < this -> high())
        high = this -> high();
    else
    {
        high =  this -> high();
    }

    int a = high - low;
    if (a>=0)
        return a;
    else
        return 0;
}
And throw this code away. It will not compile. The "this" keyword can only be used in non-static member functions of a class. And, even if you made this function a member function, the logic is cocked up.
grumpy is offline   Reply With Quote
Old Dec 8th, 2006, 10:53 PM   #22
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
double getOverlap (Span *span1, Span *span2)

I'm stuck then! I need to think of a way to implement the same task using pointers in the parameters.

If
this
doesn't work, what can I use??
aznballerlee is offline   Reply With Quote
Old Dec 8th, 2006, 11:21 PM   #23
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,223
Rep Power: 5 grumpy is on a distinguished road
Read my second last post (#20 in this thread): the answer is there, but you will have to think about it.
grumpy is offline   Reply With Quote
Old Dec 8th, 2006, 11:48 PM   #24
aznballerlee
Hobbyist Programmer
 
Join Date: Nov 2006
Posts: 111
Rep Power: 2 aznballerlee is on a distinguished road
I used the same idea as post 20. Your advice was to use the ->
since we are dealing with pointer parameters.

double getOverlap (Span *span1, Span *span2)
{
	int high, low;
	if (span1 -> low() > span2 -> low())
		low = span1 -> low();
	else
	{   
		low = span2 -> low();
	}

	if (span1 -> high() < span2 -> high())
		high = span1 -> high();
	else
	{
		high =  span2 -> high();
	}

	int a = high - low;
	if (a>=0)
		return a;
	else
		return 0;
}
aznballerlee is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to create struct containing variable array struct shoeyfighter C 14 Nov 6th, 2006 3:26 AM
Casting a struct to s aimilar struct shoeyfighter C 6 Oct 27th, 2006 2:59 PM
struct question n00b C++ 9 Oct 15th, 2006 11:26 AM
Appreciate comments on some linked list code Jessehk C 5 Jul 20th, 2006 7:59 PM
confusing question from assignment silvia C++ 1 Jul 29th, 2005 4:29 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:29 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC