472,959 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1826
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
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
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
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
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
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
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
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
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
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
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.