2015-09-07 26 views
0

嘗試使用2010 Express版本再次啓動Visual C++。跨項目使用的函數定義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

聽起來是C++/clr –

+0

你能提供一個代碼示例嗎? –

+0

它看起來像你缺少一個前向聲明和一個marshal_as本地CLI轉換 – Niall

回答

0
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; 
} 

這工作!感謝您的提示。

相關問題