473,513 Members | 2,561 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The problem of inheritance? Why can't it overload the private same name function ?Help?

error!
33 E:\program\wukexin\file\file.h `bool My_lib::Cfileinfo::initialize(const
char*)' is private
19 E:\program\wukexin\dir\dir.cpp within this context
////////////////////////////////////
#ifndef fileH
#define fileH
////
#include "windows.h"
namespace My_lib{
class Cfileinfo{
public:
Cfileinfo(const std::string& name);
Cfileinfo(const char* name);
virtual ~Cfileinfo();
virtual void display();
virtual unsigned long size() const;
protected:
HANDLE m_hfile;
WIN32_FIND_DATA m_wfd;
private:
Cfileinfo(const Cfileinfo& X);
Cfileinfo operator= (const Cfileinfo& X);
bool initialize(const char* name);// linenumber 33
bool clean();
};
}//end namespace My_lib

#endif //fileH
/*******************************
#ifndef dirH
#define dirH
//
#include "file\file.h"
namespace My_lib{
class Cdirinfo:public Cfileinfo{
public:
Cdirinfo(const char* path);
Cdirinfo(const std::string& path);
~Cdirinfo();
void display();
private:
std::list<std::string> m_record;
bool intialize(const char* name);
void traverse();
void scan(const char* path);
Cdirinfo(const Cdirinfo& X);
Cdirinfo operator= (const Cdirinfo& X);
};
}
#endif// dirH
/*****************************
namespace My_lib{
Cdirinfo::Cdirinfo(const char* path):Cfileinfo(path){
//#ifdef DEBUG
Ctracer tracer( std::string("Cdirinfo"),std::string(path) );
//#endif //debug
if( false==initialize(path) ){ //linenumber 19
cout<<"Cdirinfo::initialize("<<path<<") run failed!\n";
throw;
}
}
}//end

Dec 21 '05 #1
5 1849
Hi,
If you think CfileInfo::Initialize will be useful to its child classes
like in Cdirinfo, then make the method CfileInfo::Initialize protected.
A private method cant be accessed by its child classes because its
"private".

And you cant overload because the private Initialize method does exist
in Cdirinfo, its just that you are not allowed to access it.

Regards,
Sumanth

Dec 21 '05 #2
dragon wrote:
error!
33 E:\program\wukexin\file\file.h `bool My_lib::Cfileinfo::initialize(const
char*)' is private
19 E:\program\wukexin\dir\dir.cpp within this context
////////////////////////////////////
#ifndef fileH
#define fileH
////
#include "windows.h"
namespace My_lib{
class Cfileinfo{
public:
Cfileinfo(const std::string& name);
Cfileinfo(const char* name);
virtual ~Cfileinfo();
virtual void display();
virtual unsigned long size() const;
protected:
HANDLE m_hfile;
WIN32_FIND_DATA m_wfd;
private:
Cfileinfo(const Cfileinfo& X);
Cfileinfo operator= (const Cfileinfo& X);
bool initialize(const char* name);// linenumber 33
bool clean();
};
}//end namespace My_lib

#endif //fileH
/*******************************
#ifndef dirH
#define dirH
//
#include "file\file.h"
namespace My_lib{
class Cdirinfo:public Cfileinfo{
public:
Cdirinfo(const char* path);
Cdirinfo(const std::string& path);
~Cdirinfo();
void display();
private:
std::list<std::string> m_record;
bool intialize(const char* name);
void traverse();
void scan(const char* path);
Cdirinfo(const Cdirinfo& X);
Cdirinfo operator= (const Cdirinfo& X);
};
}
#endif// dirH
/*****************************
namespace My_lib{
Cdirinfo::Cdirinfo(const char* path):Cfileinfo(path){
//#ifdef DEBUG
Ctracer tracer( std::string("Cdirinfo"),std::string(path) );
//#endif //debug
if( false==initialize(path) ){ //linenumber 19
cout<<"Cdirinfo::initialize("<<path<<") run failed!\n";
throw;
}
}
}//end


Your question from the subject line is "Why can't [i] overload the
private same name function?" Try qualifying your call to initialize:

Cdirinfo::initialize(path)

Cheers! --M

Dec 21 '05 #3

dragon wrote:
#include "file\file.h"
namespace My_lib{
class Cdirinfo:public Cfileinfo{
public:
Cdirinfo(const char* path);
Cdirinfo(const std::string& path);
~Cdirinfo();
void display();
private:
std::list<std::string> m_record;
bool intialize(const char* name);
void traverse();
void scan(const char* path);
Cdirinfo(const Cdirinfo& X);
Cdirinfo operator= (const Cdirinfo& X);
};
}
#endif// dirH
/*****************************


If you actually copied this in from your code then your problem is a
typo. In Cdirinfo the function is intialize(). No reason why a compiler
should complain here, it's a perfectly legitimate name for a function.

Dec 21 '05 #4
Earl Purple wrote:
dragon wrote:
#include "file\file.h"
namespace My_lib{
class Cdirinfo:public Cfileinfo{
public:
Cdirinfo(const char* path);
Cdirinfo(const std::string& path);
~Cdirinfo();
void display();
private:
std::list<std::string> m_record;
bool intialize(const char* name);
void traverse();
void scan(const char* path);
Cdirinfo(const Cdirinfo& X);
Cdirinfo operator= (const Cdirinfo& X);
};
}
#endif// dirH
/*****************************


If you actually copied this in from your code then your problem is a
typo. In Cdirinfo the function is intialize(). No reason why a compiler
should complain here, it's a perfectly legitimate name for a function.


Good catch!

Dec 21 '05 #5
If you actually copied this in from your code then your problem is a
typo. In Cdirinfo the function is intialize(). No reason why a compiler
should complain here, it's a perfectly legitimate name for a function.


Thank you very much. I type my function error!. But I have learned that it
"never redefine an inherited nonvirtual function" from effective C++, Why?
If I overload the private same function, through compiler( gcc 3.4.2), why
not I redefined an inherited "private" novirtual function. Could you tell
me. I lookup many books, but
I have not found my answer.
Dec 22 '05 #6

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

Similar topics

0
1446
by: John Hunter | last post by:
I am using pycxx 5.2.2 to implement some extension code and have a problem relating to inheritance. I have a pure virtual base class and two concrete derived classes. In the code below, everthing...
2
4361
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
2
991
by: Martin Jensen | last post by:
Hi I have a problem with Qt. My class definition is this: class Button : public QObject, public Tk_Object { Q_OBJECT public: Button() {} Button(Tk_Object &p); ~Button();
5
2103
by: Jeff Greenberg | last post by:
Not an experienced c++ programmer here and I've gotten myself a bit stuck. I'm trying to implement a class lib and I've run into a sticky problem that I can't solve. I'd appreciate any help that I...
14
12879
by: Steve Jorgensen | last post by:
Recently, I tried and did a poor job explaining an idea I've had for handling a particular case of implementation inheritance that would be easy and obvious in a fully OOP language, but is not at...
45
6310
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
4
1557
by: srinivasarao_moturu | last post by:
class ABC { public : virtual void operation1(); virtual void operation2(); virtual int GetValue(); virtual char GetValue(); virtual void SetValue(int); virtual void SetValue(char); }
3
8288
by: needin4mation | last post by:
The code is taken from the book Professional C#: abstract class GenericCustomer { private string name; public GenericCustomer(string name) { this.name = name; }...
36
2657
by: Pacific Fox | last post by:
Hi all, haven't posted to this group before, but got an issue I can't work out... and hoping to get some help here ;-) I've got a base object that works fine with named arguments when called...
0
7259
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
7158
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
7380
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,...
0
7535
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
7098
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
4745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3232
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
3221
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.