从不同的类更改文本框的值? [英] Change value of textBox from different class?

查看:102
本文介绍了从不同的类更改文本框的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个C ++ / CLI的形式与 TextBox1的键,一类叫做在另一头文件,是什么我可以做,如果我想改变直接,在虚拟类存在的 textbox1.Text 由函数的值?

If I have a C++/CLI form with textbox1 and a class called Dummy in another header file, what can I do if I want to change "directly" the value of textbox1.Text by a function exists in Dummy class?

推荐答案

C ++做单通编译。这意味着你不能使用的东西,直到编译器已经看到了。

C++ does single-pass compilation. That means you can't use something until the compiler has already seen it.

当您在使用互为两个班,这可能会非常棘手。幸运的是,C ++还允许向声明,它告诉编译器这是一类或函数签名我会为您提供更高。

When you have two classes using each other mutually, that can be tricky. Luckily C++ also allows forward declaration, which tells the compiler "Here is the signature for a class or function I'm going to provide you with later".

在一般情况下,提供编译器的下面,顺序如下:

In general, provide the compiler with the following, in this order:

  • 类向前声明

  • forward declaration of classes

ref class Dummy;
ref class MyForm;

  • 类定义

  • class definitions

    ref class Dummy { ... };
    ref class MyForm { ... };
    

  • 类的成员函数的定义

  • class member function definitions

    void Dummy::DoIt()
    {
        myForm->textBox1->Text = whatever;
    }
    

  • 通常情况下,唯一需要的就是要放在一个.cpp文件中的函数定义,并确保.cpp文件的#include S对于每一个类的头文件。对于你的问题,那会意味着你应该把这个行 Dummy.cpp ,其中既包括 Dummy.h myform.h

    Often, the only thing needed is to put function definitions in a .cpp file, and make sure that .cpp file #includes the header file for every class. For your problem, that'd mean you should put this line in Dummy.cpp, which includes both Dummy.h and myform.h.

    这篇关于从不同的类更改文本框的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆