0

オブジェクト obj に含まれる値を関数に渡そうとしていますが、からにaddnode変換できないというコード ブロック エラーが発生します。関数へのポインターを渡すためにこれをどのように書き直すことができるでしょうか 。コードは次のとおりです。objmos*mosaddnode

#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.
}   
4

1 に答える 1

3

関数の宣言と定義が一致しません。を渡したい場合はmos*、宣言を次のように変更します。

void addnode(mos*);

コンパイラが への呼び出しを確認した時点addnodemosmos*.

于 2013-04-04T16:35:57.947 に答える