我想知道是否有一種方式在C++知道什麼叫一個函數?像Java或JavaScript中的this關鍵字一樣。如何引用C++中的函數?
例如,我有一個名爲insert的函數,它將一個項插入鏈表中,我希望調用那些函數insert的鏈表調用兩個其他函數。我會怎麼做?
我現在有這個權利,這有效嗎?
bool linked_list::insert(int i)
{
bool inserted = false;
if(this.is_present(i)) /* function is_present is defined earlier checks if an int is already in the linked-list. */
{
inserted = true // already inside the linked-list
}
else
{
this.Put(0, i); /* function Put is defined earlier and puts an int in a linked-list at a given position (first param.). */
inserted = true; // it was put it.
}
return inserted;
}
您的術語有點不正確。鏈表不調用'insert';在鏈表上調用'insert'。該函數被其他使用它的函數調用。 –