問題:通過C++函數,我需要運行線程函數,該函數又調用另一個Singleton C++函數。這個被調用的函數會調用C函數(它運行一個無限循環來改變每10毫秒的嵌入式系統狀態)。如何在C++中調用函數內部的函數?
問題:如何在C++中調用函數內的函數?我是否需要分配實例來調用第二個函數?
請參考示例代碼並給出您的想法是否正確或錯誤。
我有一個單獨的類說辛格爾頓
class Singleton
{
private : // constructors and values
public :
void runThread();
Singleton getInstance();
bool ChangeStatus(int a);
};
void Singleton:: runThread()
{
changeStatus(7); // is this is right way to call function inside function
}
bool Singleton:: changeStatus(int a);
{
// This calls C function which changes the status of embedded system
}
void main()
{
// create instance of singleton class
Singleton *instance1 = Singleton::getInstance();
instance1.runThread();
/* will this call the function changeStatus and will this
changeStatus function will change status of embedded system
assuming the c function to change status is working fine.
*/
}
請無視基本的語法錯誤。
當我打電話從主要的runThread
功能將它成功地調用changeStatus功能還是需要指定一個多實例內runThread調用changeStatus像辛格爾頓 instance2 = Singleton::getInstance(); instance2->changeStatus
您有問題要問?如果是這樣,那是什麼? – 2012-03-06 22:30:59
對不起基思,我不是很清楚。我更新了我的問題。請參考它,並分享您的想法 – samantha 2012-03-06 22:36:45
** void ** getInstance(); ? instance1 **。** runThread(); ? – 2012-03-06 22:37:47