[問題] 用 fstream 讀入類別並呼叫成員函式

看板C_and_CPP (C/C++)作者 (sherry)時間13年前 (2013/04/28 13:34), 編輯推噓2(208)
留言10則, 6人參與, 最新討論串1/2 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Linux 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) 問題(Question): 請問如果在int main檔裡寫ifstream INPUT("Input.txt",ios::in) 要怎麼用input.txt裡的函式functionINInputFile?? 餵入的資料(Input): 預期的正確結果(Expected Output): 錯誤結果(Wrong Output): error. input not declared in this scope 程式碼(Code):(請善用置底文網頁, 記得排版) Input.txt class Input{ functionINInputFile(); }; main.cpp class AOB{ ifstream input("Input.txt",ios::in); input IN; IN.functionINInputFile; }; 補充說明(Supplement): -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.123.175

04/28 13:52, , 1F
不可能
04/28 13:52, 1F

04/28 14:44, , 2F
這應該只有動態語言才做的到吧,用eval之類的
04/28 14:44, 2F

04/28 16:34, , 3F
可以,用 std::function<T>
04/28 16:34, 3F

04/28 16:44, , 4F
definition 在 input 就稍微麻煩而已
04/28 16:44, 4F

04/28 17:34, , 5F
用root/c++ interpreter
04/28 17:34, 5F

04/28 18:02, , 6F
關鍵字,dlopen(),dlsym()。我的話會用(Varadic)MACRO
04/28 18:02, 6F

04/28 18:04, , 7F
加上 varadic template, 內部呼叫有 C Mangled name
04/28 18:04, 7F

04/28 18:05, , 8F
的函式,至於要不要叫用 execve() 就看你了
04/28 18:05, 8F

04/28 18:51, , 9F
原來有方法,受教了...去查查看
04/28 18:51, 9F

04/28 19:37, , 10F
我覺得你需要的是script interpreter
04/28 19:37, 10F
文章代碼(AID): #1HVBK1QW (C_and_CPP)
文章代碼(AID): #1HVBK1QW (C_and_CPP)