error!
33 E:\program\wuke xin\file\file.h `bool My_lib::Cfilein fo::initialize( const
char*)' is private
19 E:\program\wuke xin\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(cons t 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::Cdiri nfo(const char* path):Cfileinfo (path){
//#ifdef DEBUG
Ctracer tracer( std::string("Cd irinfo"),std::s tring(path) );
//#endif //debug
if( false==initiali ze(path) ){ //linenumber 19
cout<<"Cdirinfo ::initialize("< <path<<") run failed!\n";
throw;
}
}
}//end 5 1856
Hi,
If you think CfileInfo::Init ialize will be useful to its child classes
like in Cdirinfo, then make the method CfileInfo::Init ialize 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
dragon wrote: error! 33 E:\program\wuke xin\file\file.h `bool My_lib::Cfilein fo::initialize( const char*)' is private 19 E:\program\wuke xin\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(cons t 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::Cdiri nfo(const char* path):Cfileinfo (path){ //#ifdef DEBUG Ctracer tracer( std::string("Cd irinfo"),std::s tring(path) ); //#endif //debug if( false==initiali ze(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::initi alize(path)
Cheers! --M
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.
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! 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 works fine
in that the derived classes can use the base method get, but if I try
and add a method only available to Derived2, eg, get2, I get a...
|
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
files containing some templates: adjacency_list.hpp and mem_fn.hpp can
not compile.
Does anyone have any solutions?
|
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();
|
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 can get!
Consider 3 classes in the following heirarchy:
base
/ \
deriv1 deriv2
\
|
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 all obvious in VBA which lacks
inheritance. I'm trying the explanation again now.
I often find cases where a limited form of inheritance would...
| |
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 parameters, I get CS1501 (no method
with X arguments). Here's a simplified example which mimics the
circumstances:
namespace InheritError {
//...
|
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);
}
|
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;
}...
|
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
on it's own. However when I call the child object I get an error
" has no properties (in firefox)."
I simple test:
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |