c++ - 如何使函数在C++中返回结构指针

标签 c++

我想让函数返回特定节点的地址。但是编译器是 未检测到我创建的节点数据类型结构。

struct node
{
int data;

node *link;
};

node *header,*current;
node traverse(int pos);


node *Linkedlist::traverse(int pos)
{
    int location = 0;  
    current->link = header->link;
    node *address = new node;
    address->data = NULL;
    address->link = NULL;


    while(current->link != NULL)
    {

        if(location == pos)
        {
            cout <<current->link->data <<" "<< endl; 
            address->link=current->link;
        }
        location ++;
        current->link = current->link->link;

    }


    return  address->link;
}

最佳答案

改变

return  *address;

return  address;

关于c++ - 如何使函数在C++中返回结构指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14300578/

相关文章:

c++ - 如何在 C++ 的谷歌测试中匹配双 vector 的元素?

c++ - 在 C++ 中重命名名称中带有破折号的文件

c++ - 可变参数到 lambda 表达式

c++ - 字符串数组的奇怪内存行为

javascript - 如何在我的网站中使用 Chrome 扩展功能 (NaCl)?

c++ - C++将字符串转换为int

c++ - C++0x 是否支持匿名内部类?

python - 有什么方法可以将用C++创建的变量加载到python解释器中吗?

c++ - 循环的编译器优化

c++ - 在 xcode 中设置 C++ 编译标志