473,508 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

do static functions get inherited?

I have a confusion.
Do static member functions of base class get inherited to derived
class?

I searched for this answer but nowhere I get any referencec saying
"derived class inherits static functions with other member functions
of the base class".
regds,
arj
Jul 22 '05 #1
8 7678
ashok wrote:
I have a confusion.
Do static member functions of base class get inherited to derived
class?
Yes.
I searched for this answer but nowhere I get any referencec saying
"derived class inherits static functions with other member functions
of the base class".


Any member function is inherited (unless it's private). It may be
inaccessible due to name hiding, but it is always there.

Are you experiencing any particular problem?

V
Jul 22 '05 #2
>Any member function is inherited

What about assignment operators?
Jul 22 '05 #3
DaKoadMunky wrote:
Any member function is inherited

What about assignment operators?


Yes. The problem is that they are hidden by class' own assignment
operator (even if it's compiler-defined).

#include <iostream>
struct B {
B& operator=(const B&) {
std::cout << "B=B\n"; return *this; }
};

struct D : B {};

int main() {
D d1, d2;
d1.B::operator=(d2);
}

Constructors and destructors are not inherited. But those are
truly special functions.

V
Jul 22 '05 #4
>Yes. The problem is that they are hidden by class' own assignment
operator (even if it's compiler-defined).

#include <iostream>
struct B {
B& operator=(const B&) {
std::cout << "B=B\n"; return *this; }
};

struct D : B {};

int main() {
D d1, d2;


I am hoping that Santa Claus will bring me the C++ Standard for Christmas, but
until then I will have to quote TCPPPL 2nd Ed. pg 593...

"The assignment function operator=() must be a nonstatic member function; it is
not inherited"

Maybe this is an error or has changed?

struct Base
{
void operator=(int)
{
}
};

struct Derived : Base
{
};

int main()
{
Derived d;
d = 3;

return 0;
}

The above produces an error on both Comeau and VC++.

If I introduce a using declaration into struct Derived...

struct Derived : Base
{
using Base::operator=();
};
Comeau accepts d = 3 but VC++ still does not.

I don't know which one is correct.
Jul 22 '05 #5

"DaKoadMunky" <da*********@aol.com> wrote in message
news:20***************************@mb-m14.aol.com...
Yes. The problem is that they are hidden by class' own assignment
operator (even if it's compiler-defined).

#include <iostream>
struct B {
B& operator=(const B&) {
std::cout << "B=B\n"; return *this; }
};

struct D : B {};

int main() {
D d1, d2;

I am hoping that Santa Claus will bring me the C++ Standard for Christmas,

but until then I will have to quote TCPPPL 2nd Ed. pg 593...

"The assignment function operator=() must be a nonstatic member function; it is not inherited"

Maybe this is an error or has changed?

struct Base
{
void operator=(int)
{
}
};

struct Derived : Base
{
};

int main()
{
Derived d;
d = 3;

return 0;
}

The above produces an error on both Comeau and VC++.

If I introduce a using declaration into struct Derived...

struct Derived : Base
{
using Base::operator=();
};
Comeau accepts d = 3 but VC++ still does not.

I don't know which one is correct.

Question about this topic:

Why should I overload the operator= instead of create a copy constructor?

ernesto
Jul 22 '05 #6
Copy constructor is used to construct an object that is a copy of an existing
object...

T t1;
T t2(t1);

Copy assignment is used to assign an existing object to an existing object...

T t3,t4;
t3 = t4;
Jul 22 '05 #7
>>Why should I overload the operator= >>instead of create a copy constructor?

Copy constructor is used to construct an object that is a copy of an existing
object...

T t1;
T t2(t1);

Copy assignment is used to assign an existing object to an existing object...

T t3,t4;
t3 = t4;


I wanted to clarify which post I was responding to.
Jul 22 '05 #8
Victor Bazarov <v.********@comAcast.net> wrote in message news:<Ok****************@newsread1.dllstx09.us.to. verio.net>...
ashok wrote:
I have a confusion.
Do static member functions of base class get inherited to derived
class?


Yes.
I searched for this answer but nowhere I get any referencec saying
"derived class inherits static functions with other member functions
of the base class".


Any member function is inherited (unless it's private). It may be
inaccessible due to name hiding, but it is always there.

Are you experiencing any particular problem?

V


I believed private members were inherited, but inaccessible. I believe
they are there but you can't call them directly. Could you clarify
this point?

Marcelo Pinto
Jul 22 '05 #9

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

Similar topics

10
2491
by: porneL | last post by:
How do I use static functions/properties with inheritance? I've found it very problematic. class Foo { static function A() {/* ??? */::B(); } static function B() {echo 'Foo';} }; class...
1
7006
by: Dave | last post by:
In Exceptional C++, the following code snippet appears at the bottom of page 197: template<class T> class Array : private ArrayBase, public Container { typedef Array AIType; public: Array(...
8
1884
by: Ernst Murnleitner | last post by:
Hello Readers, Is there a way that only one class can construct a class A and its inherited classes A2, A3 etc.? I want to construct a class A (and the inherited classes A2, A3 etc.) from a...
15
6556
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
13
7671
by: Adam H. Peterson | last post by:
I just made an observation and I wondered if it's generally known (or if I'm missing something). My observation is that static protected members are essentially useless, only a hint to the user. ...
1
1227
by: Thomas Fritzen | last post by:
I have a problem with static functions and inheritance as demonstrated by the below samples using System; namespace ConsoleApplication1 { class x { public static void Log() {...
5
1794
by: Digital Puer | last post by:
Hi, I've inherited a bunch of C code that needs to be called from a C++ framework, so I thought it would be good to put these C functions into C++ classes for better organisation. What are best...
1
1590
by: wes | last post by:
Hi, Is there anyway to disambiguate multiply inherited static class functions? template<T> class A { static doit() {} }
13
20745
by: learning | last post by:
Hi I have a static class written by other team which encapsulates a database instance. but I need to extend it to incldue other things. I know that C# static class is sealed and can;t be inherited...
0
7225
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
7383
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7046
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3194
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1557
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.