![](/img/trans.png)
[英]How to write a template function that can handle object or pointer function calls ?
[英]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.