473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

accessing parent class method

In my program I am using two classes foo1, the parent class, and foo2
the child class!
foo2 has overloaded inserter and extractor operator, but so does foo1!
How can I access foo1 inserter or extractor?
Thanks
Jun 1 '08 #1
3 1913
ArbolOne wrote:
In my program I am using two classes foo1, the parent class, and foo2
the child class!
foo2 has overloaded inserter and extractor operator, but so does foo1!
How can I access foo1 inserter or extractor?
Post your code. It is easier when there is substance to the discussion.

Meanwhile, here is the example:

struct foo {
void foobar();
};

struct bar : foo {
void foobar();
};

int main() {
bar b;
b.foobar(); // calls bar::foobar
b.foo::foobar(); // call foo::foobar
}

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jun 1 '08 #2
On 2008-06-01 03:07, Victor Bazarov wrote:
ArbolOne wrote:
>In my program I am using two classes foo1, the parent class, and foo2
the child class!
foo2 has overloaded inserter and extractor operator, but so does foo1!
How can I access foo1 inserter or extractor?

Post your code. It is easier when there is substance to the discussion.

Meanwhile, here is the example:

struct foo {
void foobar();
};

struct bar : foo {
void foobar();
};

int main() {
bar b;
b.foobar(); // calls bar::foobar
b.foo::foobar(); // call foo::foobar
}
I would call it bad style to explicitly call a parent's implemenetation
of a function (and bad design if you have to), unless it is done in the
child's implementation of the same function:

#include<iostream>

struct foo1 {
virtual void foobar() {
std::cout << "foo1\n";
}
};

struct foo2 : public foo1 {
virtual void foobar() {
std::cout << "foo2\n";
foo1::foobar(); // Call foo1's foobar()
}
};

int main() {
foo1* f = new foo1();
f->foobar();
delete f;
f = new foo2();
f->foobar();
}

--
Erik Wikström
Jun 1 '08 #3
On Jun 1, 3:57 am, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2008-06-01 03:07, Victor Bazarov wrote:
ArbolOne wrote:
In my program I am using two classes foo1, the parent class, and foo2
the child class!
foo2 has overloaded inserter and extractor operator, but so does foo1!
How can I access foo1 inserter or extractor?
Post your code. It is easier when there is substance to the discussion.
Meanwhile, here is the example:
struct foo {
void foobar();
};
struct bar : foo {
void foobar();
};
int main() {
bar b;
b.foobar(); // calls bar::foobar
b.foo::foobar(); // call foo::foobar
}

I would call it bad style to explicitly call a parent's implemenetation
of a function (and bad design if you have to), unless it is done in the
child's implementation of the same function:

#include<iostream>

struct foo1 {
virtual void foobar() {
std::cout << "foo1\n";
}

};

struct foo2 : public foo1 {
virtual void foobar() {
std::cout << "foo2\n";
foo1::foobar(); // Call foo1's foobar()
}

};

int main() {
foo1* f = new foo1();
f->foobar();
delete f;
f = new foo2();
f->foobar();

}

--
Erik Wikström
I got it now!
Thanks.
Jun 1 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Suzanne Vogel | last post by:
Hi, Given: I have a class with protected or private data members, some of them without accessor methods. It's someone else's class, so I can't change it. (eg, I can't add accessor methods to the...
2
by: Havatcha | last post by:
Does anyone know the syntax for accessing assignment operators in a Parent Class from a Child Class? If so, would be great if you could post a brief example here. Thanks.
2
by: Rustam Asgarov | last post by:
how can i access variables defined in the parent class from the child class: By some way other than passing as parameter to constructor. I mean. class Parent{ public int b; public...
4
by: Hadi | last post by:
Hello, Say I have three classes inheritance A <-- B <-- C And in A I have the Create method: class A { public override bool Create() {
3
by: Peteroid | last post by:
Is it possible to make a public parent class method unavailable (i.e., generate an error at compile time) to a particular child class? For example, say a parent class has a public method Add( )....
11
by: alex | last post by:
Hi, how can I access / set properties of controls in other forms. i.e. mdi parent of mdi child mdi child of mdi child mdi child of mdi parent Thanks Alex
1
by: Xarious | last post by:
Hi all, I need to bring up a form off of my base win form and then, depending on which button the user clicks, perform a function that is in my base form. I can create an instance and show the...
3
by: free2cric | last post by:
Hi I have a simple problem class aaaa { public: int a; public: int getParentVar() }
14
by: Jo | last post by:
Hi, Is there a generic way to access the (virtual) functions in the base class of a class? Like in: if (!this->Foo(something)) return(((Base*)this)->Foo(something)); // for a normal member...
3
by: GTAPy | last post by:
Hello Python Dev. i am new to Python, i am stuck in one of the classes instantiation with confusing __init__ , here the details : i have 2 classes Class A: def __init__(self): ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.