代码之家  ›  专栏  ›  技术社区  ›  Wyllow Wulf

要在项目Visual C中使用的函数定义++

  •  0
  • Wyllow Wulf  · 技术社区  · 9 年前

    尝试使用2010速成版重新启动Visual C++。

    想弄明白些什么。

    如果在 Project.cpp 文件,为什么我不能在 Form1.h 文件,特别是私有文件: System::Void Form1_Load ?

    我收到此错误:

    1>c:\users\boss\documents\visual studio 2010\projects\second\second\Form1.h(94): error C3861: 'Function': identifier not found
    

    有没有办法定义一个函数,以便它可以在任何地方使用?

    在Form1.h中:

    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
        this->txtMain->Text += FunctionX("Data");
        this->txtMain->SelectionStart = this->txtMain->Text->Length;
    }
    

    在Project.cpp中:

    std::string FunctionX(std::string message) {
        // other code here
        return message;
    }
    
    1 回复  |  直到 9 年前
        1
  •  0
  •   Wyllow Wulf    9 年前
    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
    extern std::string FunctionX(std::string message);
    this->txtMain->Text += msclr::interop::marshal_as<System::String^>(FunctionX("Data"));
    this->txtMain->SelectionStart = this->txtMain->Text->Length;
    }
    

    这奏效了!谢谢你的提示。