English 中文(简体)
Visual++从main打印,并继承列表框中的视觉形式
原标题:Visual ++ print from main with inheritance on visual form in listbox

I´ve made a "main" class lets call it A(Veichle), and i have two classes that inherits from A Lets call them B(Car) and C(MC). i also have a handler lets call it "D" that binds A,B and C. Then i have the Form1 class lets call that E(Visual)

我想在列表框中的视觉形式“E”上打印出来自A的私人成员

如果我尝试ex)

这->;列表框1->;项目->;添加(X.veichles[i]->;getBrand());

它抱怨维奇尔斯是D的私人会员。

我该怎么避开它?

问题回答

private意味着其他类不允许访问。

您应该创建一个公共访问器函数。例如,GetVehicleByIndex(int idx)

您的代码如下所示:

A* pVehicle = X.GetVehicleByIndex(i);
if (pVehicle) // assuming NULL indicates error
    add(pVehicle->getBrand());
else
    // react on error

那我就可以回答我自己的问题了。

在与form1.h通信的类的handler.cpp中,您创建了一个函数:

void getPersonByIndex(i);

return this->person[i]->getSurName();

然后在<code>form1.h</code>中,您可以写:

for(int i=0;i<this->getNrOfPersons;i++)

String^ str = new String(comm.getPersonByIndex(i)); //this conversion was my problem

this->listbox->beginupdate();
this->listbox->items->add(str);
this->listbox->endupdate();




相关问题
Subclass check, is operator or enum check

A couple of friends was discussing the use of inheritance and how to check if a subclass is of a specific type and we decided to post it here on Stack. The debate was about if you should implement a ...

C++ Class Inheritance problem

Hi I have two classes, one called Instruction, one called LDI which inherits from instruction class. class Instruction{ protected: string name; int value; public: Instruction(string ...

Overloading a method in a subclass in C++

Suppose I have some code like this: class Base { public: virtual int Foo(int) = 0; }; class Derived : public Base { public: int Foo(int); virtual double Foo(double) = 0; }; ...

Embedding instead of inheritance in Go

What is your opinion of this design decision? What advantages does it have and what disadvantages? Links: Embedding description

Extending Flex FileReference class to contain another property

I want to extend the FileReference class of Flex to contain a custom property. I want to do this because AS3 doesn t let me pass arguments to functions through event listeners, which makes me feel sad,...

Interface Inheritance in C++

I have the following class structure: class InterfaceA { virtual void methodA =0; } class ClassA : public InterfaceA { void methodA(); } class InterfaceB : public InterfaceA { virtual ...

热门标签