问题:通过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