|
-
Oct 10th, 2003, 02:58 AM
#1
Thread Starter
Fanatic Member
inherited funcitons
Ok, having a few inheritence problems.
I have a class CMatrix;
It has a void Print() function and a constructor that takes 3 parameters (rows, cols, fill)
I also have a class CPoint, which uses CMatrix as a base.
When constructed, it takes size and fill, and calls the CMatrix constructor (1, size, fill)
No Problem yet, but how can i call a CPoint object to .Print(), and get it to use the CMatrix Print() Function without doing this:
void CPoint::Print()
{
CMatrix::Print();
}
Is there any better way?
Thanks
sql_lall 
-
Oct 10th, 2003, 04:07 AM
#2
Hyperactive Member
So, you want to use CMatrix's print() in CPoint's print() function?
If your going to use inheritance, and print() is common to both classes, you can just use CMatrix's print() function (it carries over to CPoint after all). So, if you wanted to use the print() function in a driver program:
CPoint declaration:
Code:
class CPoint: public CMatrix;
print() usage in a driver program:
Code:
CPoint pt(1,2,3);
pt.print(); //print() carries over from CMatrix
Does that help any?
Last edited by Comreak; Oct 10th, 2003 at 04:10 AM.
C.O.M.R.E.A.K.: Cybernetic Obedient Machine Responsible for Exploration and Accurate Killing
-
Oct 10th, 2003, 03:43 PM
#3
To clarify: if you don't actually do anything in the CPoint version of print other than calling the base version, simply omit the method completly from CPoint.
How is a point a matrix btw?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Oct 11th, 2003, 05:26 AM
#4
Thread Starter
Fanatic Member
ok...nice
So, if i just leave out the function entirely from the Point class, then when i call
myPoint.Print()
then this will default to the Matrix Print() funciton??
Oh, and an n-dimensional point can be stored as a 1xn or nx1 matrix. Then you can do tranformations by using matrix multiplication, or do scaling, subtraction etc easily.
sql_lall 
-
Oct 11th, 2003, 02:20 PM
#5
Hyperactive Member
Re: ok...nice
Originally posted by sql_lall
So, if i just leave out the function entirely from the Point class, then when i call
myPoint.Print()
then this will default to the Matrix Print() funciton??
Yes, that's correct. CPoint inherits all of it's qualities from CMatrix, including print().
C.O.M.R.E.A.K.: Cybernetic Obedient Machine Responsible for Exploration and Accurate Killing
-
Oct 12th, 2003, 04:25 AM
#6
Thread Starter
Fanatic Member
-
Oct 12th, 2003, 07:43 AM
#7
Code:
class CMatrix
{
public:
void Print() const;
};
void CMatrix::Print() const
{
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|