문제점 : 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 함수를 호출하거나 수정 한 후 (서면 나는 코드에서 싱글 instance2 = Singleton::getInstance(); instance2->changeStatus
질문이 있으십니까? 그렇다면 무엇입니까? –
미안 Keith, 나는 아주 명확하지 않았다. 나는 내 질문을 업데이트했다. 그것을 참조 하시고 친절하게 여러분의 생각을 나누십시오. – samantha
** 무효 ** getInstance(); ? instance1 **. ** runThread(); ? –