N
Nephi Immortal
I discussed functionoids and pointer to member functions a long time
ago. The template is the best option over functionoids because of the
performance issue. Unfortunately, template does not support pointer
to member function array.
I am surprised to see that C++ Compiler reports an error to say any
member function cannot access to protected from base class, but
ordinary function worked. Very absurb?
class Obj1
{
protected:
static void Run1()
{
}
void errRun1()
{
}
};
class Obj2
{
protected:
static void Run2()
{
}
void errRun2()
{
}
};
class Obj3
{
protected:
static void Run3()
{
}
void errRun3()
{
}
};
class Obj :
public Obj1,
public Obj2,
public Obj3
{
public:
void Run( int index )
{
static void ( * const pRun[ 3 ] )() =
{
Run1,
Run2,
Run3
};
pRun[ index ]();
}
void errRun( int index )
{
static void ( Obj::* const pRun[ 3 ] )() =
{
&Obj1::errRun1,
&Obj2::errRun2,
&Obj3::errRun3
};
( this->*pRun[ index ] )();
}
};
int main()
{
Obj obj;
obj.Run( 0 );
obj.Run( 1 );
obj.Run( 2 );
obj.errRun( 0 );
obj.errRun( 1 );
obj.errRun( 2 );
return 0;
}
Debug Win32 ------
Main.cpp
c:\my projects\main.cpp(315): error C2248: 'Obj1::errRun1' : cannot
access protected member declared in class 'Obj1'
c:\my projects\main.cpp(264) : see declaration of
'Obj1::errRun1'
c:\my projects\main.cpp(258) : see declaration of 'Obj1'
c:\my projects\main.cpp(316): error C2248: 'Obj2::errRun2' : cannot
access protected member declared in class 'Obj2'
c:\my projects\main.cpp(276) : see declaration of
'Obj2::errRun2'
c:\my projects\main.cpp(270) : see declaration of 'Obj2'
c:\my projects\main.cpp(318): error C2248: 'Obj3::errRun3' : cannot
access protected member declared in class 'Obj3'
c:\my projects\main.cpp(288) : see declaration of
'Obj3::errRun3'
c:\my projects\main.cpp(282) : see declaration of 'Obj3'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========
Can you please answer my question? Can hundred of base classes or
thousands of base classes be inherited into ONE derived class through
multiple inheritance? The option is the best if derived class has the
ability to create large pointer to member function array in order to
create command object.
ago. The template is the best option over functionoids because of the
performance issue. Unfortunately, template does not support pointer
to member function array.
I am surprised to see that C++ Compiler reports an error to say any
member function cannot access to protected from base class, but
ordinary function worked. Very absurb?
class Obj1
{
protected:
static void Run1()
{
}
void errRun1()
{
}
};
class Obj2
{
protected:
static void Run2()
{
}
void errRun2()
{
}
};
class Obj3
{
protected:
static void Run3()
{
}
void errRun3()
{
}
};
class Obj :
public Obj1,
public Obj2,
public Obj3
{
public:
void Run( int index )
{
static void ( * const pRun[ 3 ] )() =
{
Run1,
Run2,
Run3
};
pRun[ index ]();
}
void errRun( int index )
{
static void ( Obj::* const pRun[ 3 ] )() =
{
&Obj1::errRun1,
&Obj2::errRun2,
&Obj3::errRun3
};
( this->*pRun[ index ] )();
}
};
int main()
{
Obj obj;
obj.Run( 0 );
obj.Run( 1 );
obj.Run( 2 );
obj.errRun( 0 );
obj.errRun( 1 );
obj.errRun( 2 );
return 0;
}
Debug Win32 ------
Main.cpp
c:\my projects\main.cpp(315): error C2248: 'Obj1::errRun1' : cannot
access protected member declared in class 'Obj1'
c:\my projects\main.cpp(264) : see declaration of
'Obj1::errRun1'
c:\my projects\main.cpp(258) : see declaration of 'Obj1'
c:\my projects\main.cpp(316): error C2248: 'Obj2::errRun2' : cannot
access protected member declared in class 'Obj2'
c:\my projects\main.cpp(276) : see declaration of
'Obj2::errRun2'
c:\my projects\main.cpp(270) : see declaration of 'Obj2'
c:\my projects\main.cpp(318): error C2248: 'Obj3::errRun3' : cannot
access protected member declared in class 'Obj3'
c:\my projects\main.cpp(288) : see declaration of
'Obj3::errRun3'
c:\my projects\main.cpp(282) : see declaration of 'Obj3'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========
Can you please answer my question? Can hundred of base classes or
thousands of base classes be inherited into ONE derived class through
multiple inheritance? The option is the best if derived class has the
ability to create large pointer to member function array in order to
create command object.