我试图将obj对象中包含的值传递给函数addnode,但是我得到了一个代码块错误,它无法将obj从mos*转换为mos。如何重写此代码以传递指向函数addnode的指针,代码如下所示。
#include <iostream>
#include <sstream>
using namespace std;
struct mos
{
int x;
float y;
mos * next;
};
void addnode (mos);
int main()
{
mos * obj = new (nothrow) mos;
//Check for proper memory allocation.
if (obj == NULL)
{
cout << "\nProblem assigning memory.\n";
}
else
{
cout << "\n Memory well allocated.\n Result is: " << obj;
}
addnode(obj);
return 0;
}
void addnode (mos * head)
{
//code that adds a node to the last node in the linked list.
} 发布于 2013-04-05 00:35:58
您的函数声明和定义不匹配。如果要传递mos*,请将声明更改为:
void addnode(mos*);在编译器看到您对addnode的调用时,它只看到了一个接受mos而不是mos*的声明。
https://stackoverflow.com/questions/15816811
复制相似问题