从父类调用虚拟funktion [英] calling a virtual funktion from a parent class
问题描述
你好,
我有以下问题:
我有类似这样的结构:
命名空间A {
class X {
受保护:
虚拟无效f();
}
}
....
命名空间A {
命名空间B {
class X:public A:X {
protected:
虚拟空虚f();
}
}
}
>
在实现时我想在A :: B :: X :: f里面调用A :: X :: f()
我有尝试了以下(但它没有工作..无法访问
受保护的元素f()在一个:: X< - 令人困惑,它的父亲^^):
命名空间A {
命名空间B {
X :: f(){...
使用A :: X;
X :: f();
}
}
}
...我也尝试过这个(但它不起作用......它永远不会从父类调用f()
):
命名空间A {
命名空间B {
X :: f(){...
X :: X :: f();
}
}
}
如何从
childfunction-f()内部访问parental f() - 函数?我必须使用这些名称空间以及相同的
类名。 :(
hello,
I''ve got the following problem:
I have a construct similar like this:
namespace A {
class X {
protected:
virtual void f();
}
}
....
namespace A {
namespace B {
class X : public A:X {
protected:
virtual void f();
}
}
}
at implementation I''d like to call A::X::f() inside A::B::X::f()
I have tried the following (but it doesn''t work .. can''t get access of
protected element f() inside a::X <- confusing, its the parent ^^) :
namespace A {
namespace B {
X::f() { ...
using A::X;
X::f();
}
}
}
... also I''ve tried this (but it doesn''t work .. it never calls f()
from parent class):
namespace A {
namespace B {
X::f() { ...
X::X::f();
}
}
}
How can I get access to the parental f()-function from inside the
childfunction-f()? I must use these namespaces and also the identical
classnames. :(
推荐答案
Peter Cranz schrieb:
Peter Cranz schrieb:
hello,
我有以下问题:
我有类似这样的结构:
命名空间A {
class X {
受保护:
virtual void f();
}
}
....
名称空间A {
>
名称空间B {
class X:public A:X {
受保护:
虚拟空虚f();
}
}
}
at实现我想在A :: B :: X :: f中调用A :: X :: f()
我试过以下(但它不能工作..无法访问
受保护的元素f()在:: X< - 令人困惑,它的父亲^^):
命名空间A {
命名空间B {
X :: f(){...
使用A :: X;
X :: f ();
}
}
}
...我也试过这个(但是它不起作用..它永远不会从父类调用f()
):
命名空间A {
命名空间B {
X :: f(){...
X :: X :: f();
}
}
}
如何从
$ b内部访问父母f() - 函数$ b childfunction-f()?我必须使用这些名称空间以及相同的
类名。 :(
hello,
I''ve got the following problem:
I have a construct similar like this:
namespace A {
class X {
protected:
virtual void f();
}
}
....
namespace A {
namespace B {
class X : public A:X {
protected:
virtual void f();
}
}
}
at implementation I''d like to call A::X::f() inside A::B::X::f()
I have tried the following (but it doesn''t work .. can''t get access of
protected element f() inside a::X <- confusing, its the parent ^^) :
namespace A {
namespace B {
X::f() { ...
using A::X;
X::f();
}
}
}
... also I''ve tried this (but it doesn''t work .. it never calls f()
from parent class):
namespace A {
namespace B {
X::f() { ...
X::X::f();
}
}
}
How can I get access to the parental f()-function from inside the
childfunction-f()? I must use these namespaces and also the identical
classnames. :(
我正在使用visual c ++ ^^
I''m using visual c++ ^^
Peter Cranz schrieb:
Peter Cranz schrieb:
hello,
我遇到以下问题:
hello,
I''ve got the following problem:
[...]
[...]
在实现时我想在A :: B :: X里面调用A :: X :: f():: f()
我尝试了以下(但它不起作用..无法访问
protected element f()在一个:: X< - 令人困惑,它的父亲^^):
命名空间A {
命名空间B {
X :: f(){...
使用A :: X;
X :: f();
} < br $>
}
}
...我也试过了(但它不起作用..它从不调用f( )来自父类的
):
命名空间A {
命名空间B {
X: :f(){...
X :: X :: f();
}
}
}
如何我可以从
childfunction-f()里面访问parental f() - 函数吗?我必须使用这些名称空间以及相同的
类名。 :(
at implementation I''d like to call A::X::f() inside A::B::X::f()
I have tried the following (but it doesn''t work .. can''t get access of
protected element f() inside a::X <- confusing, its the parent ^^) :
namespace A {
namespace B {
X::f() { ...
using A::X;
X::f();
}
}
}
... also I''ve tried this (but it doesn''t work .. it never calls f()
from parent class):
namespace A {
namespace B {
X::f() { ...
X::X::f();
}
}
}
How can I get access to the parental f()-function from inside the
childfunction-f()? I must use these namespaces and also the identical
classnames. :(
完整的可编辑示例会有所帮助。
您是否尝试过:
A :: X :: f();或者this-> A :: X :: f();
在子类的f()中? br />
-
托马斯
A complete compilable example would help.
Did you try either:
A::X::f(); or this->A::X::f();
in f() of the subclass?
--
Thomas
所以这里是班级..但它们只是一块在一个复杂的
层次结构中:
.......................父母...............
命名空间omxj
{
class GateConnectCallback:public JavaObjectFrame
{
private:
std :: string getOMXGatePath_Name;
std :: string getOMXUserId_Name;
std :: string getOMXPwId_Name;
std :: string getOMXApplId_Name;
protected:
虚拟void initialize();
jmethodID getOMXGatePath_Mid;
jmethodID getOMXUserId_Mid;
jmethodID getOMXPwId_Mid;
jmethodID getOMXApplId_M id;
std :: string getMethod_Signature;
GateConnectCallback():
getOMXGatePath_Name(" getOMXGatePath" ),
getOMXUserId_Name(" getOMXUserId"),
getOMXPwId_Name(" getOMXPwId"),
getOMXApplId_Name(" getOMXApplId"),
getMethod_Signature("()Ljava / lang / String;"){};
public:
virtual void getDataFromGateConnect(JavaPackageInfoT * request,
GateConnectInfoT * gateConnectStruct);
};
};
................和孩子.................
命名空间omxj
{
命名空间xetra
{
class GateConnectCallback:public omxj :: GateConnectCallback
{
protected:
virtual void initialize();
public:
virtual void getDataFromGateConnect(JavaPackageInfoT * request,
GateConnectInfoT * gateConnectStruct);
};
};
};
...里面的omxj :: xetra :: GateConnectCallback :: initialize()我必须得到
访问xetra :: GateConnectCallback :: initialize()
..........子类的实现.............
命名空间omxj
{
命名空间xetra
{
void GateConnectCallback :: initialize()
{
//这个孩子要做的事情
omxj :: GateConnectCallback :: initialize();
}
void GateConnectCallback :: getDataFromGateConnect(JavaPa ckageInfoT * request,
GateConnectInfoT * gateConnectStruct)
{
GateConnectCallback :: GateConnectCallback :: getDataF romGateConnect(request,
gateConnectStruct);
}
}
}
希望这是足够的解释...一个可编辑的例子不可用:(
so here are the classes .. but they are only a piece inside a complex
hierarchy:
....................... the parent ...............
namespace omxj
{
class GateConnectCallback : public JavaObjectFrame
{
private:
std::string getOMXGatePath_Name;
std::string getOMXUserId_Name;
std::string getOMXPwId_Name;
std::string getOMXApplId_Name;
protected:
virtual void initialize();
jmethodID getOMXGatePath_Mid;
jmethodID getOMXUserId_Mid;
jmethodID getOMXPwId_Mid;
jmethodID getOMXApplId_Mid;
std::string getMethod_Signature;
GateConnectCallback():
getOMXGatePath_Name("getOMXGatePath"),
getOMXUserId_Name("getOMXUserId"),
getOMXPwId_Name("getOMXPwId"),
getOMXApplId_Name("getOMXApplId"),
getMethod_Signature("()Ljava/lang/String;"){};
public:
virtual void getDataFromGateConnect(JavaPackageInfoT *request,
GateConnectInfoT *gateConnectStruct);
};
};
................ and the child .................
namespace omxj
{
namespace xetra
{
class GateConnectCallback : public omxj::GateConnectCallback
{
protected:
virtual void initialize();
public:
virtual void getDataFromGateConnect(JavaPackageInfoT *request,
GateConnectInfoT *gateConnectStruct);
};
};
};
... inside omxj::xetra::GateConnectCallback::initialize() I must get
access to xetra::GateConnectCallback::initialize()
.......... the implementation of the childclass .............
namespace omxj
{
namespace xetra
{
void GateConnectCallback::initialize()
{
// something to do inside this child
omxj::GateConnectCallback::initialize();
}
void GateConnectCallback::getDataFromGateConnect(JavaPa ckageInfoT *request,
GateConnectInfoT *gateConnectStruct)
{
GateConnectCallback::GateConnectCallback::getDataF romGateConnect(request,
gateConnectStruct);
}
}
}
hope that is enough explanation ... a compilable example is not available :(
这篇关于从父类调用虚拟funktion的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!