簡體   English   中英

如何編寫模板類中聲明的函數定義,返回指向struct對象的指針?

[英]How can I write a definition of function declared in template class returning pointer to struct object?

我有這樣的代碼:

template<typename T> class Foo
{
   struct Some_struct
   {
      T object;
      Some_struct* next;
   };
public:
   Some_struct* function(); //declaration of my function
};
template<typename T> Some_struct* Foo<T>::function() //this definition is wrong
{
    //something inside
    return pointer_to_Some_struct;
}

應該如何正確定義?

您忘記將適當的范圍添加到返回類型。

這樣做:

template<typename T> typename Foo<T>::Some_struct* Foo<T>::function()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM