gpt4 book ai didi

c++ - 如何编写在模板类中返回指向结构对象的指针中声明的函数的定义?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:28:45 27 4
gpt4 key购买 nike

我有这样的代码:

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()

关于c++ - 如何编写在模板类中返回指向结构对象的指针中声明的函数的定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25314648/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com