1

私は持っていて、Node* hands[4];それを Deal のような関数に渡したいDeal(deck,hands,4,"one-at-a-time",13);

次の関数を使用すると...

void Deal(Node *deck, Node *hands[], int num_hands, const std::string &type, int num_cards)

私はこれを得る...

/tmp/ccqckP1I.o:main.cpp:(.text+0x82a): undefined reference to `CutDeck(Node*, Node*&, Node*&, std::string const&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0xb34): undefined reference to `DeleteAllCards(Node*&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0xb3f): undefined reference to `DeleteAllCards(Node*&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x1030): undefined reference to `DeleteAllCards(Node*&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x103e): undefined reference to `DeleteAllCards(Node*&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x104c): undefined reference to `DeleteAllCards(Node*&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x105a): more undefined references to `DeleteAllCards(Node*&)' follow
/tmp/ccqckP1I.o:main.cpp:(.text+0x1348): undefined reference to `CutDeck(Node*, Node*&, Node*&, std::string const&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x1492): undefined reference to `CutDeck(Node*, Node*&, Node*&, std::string const&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x15dc): undefined reference to `CutDeck(Node*, Node*&, Node*&, std::string const&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x1726): undefined reference to `CutDeck(Node*, Node*&, Node*&, std::string const&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x1870): undefined reference to `CutDeck(Node*, Node*&, Node*&, std::string const&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x1c2d): more undefined references to `CutDeck(Node*, Node*&, Node*&, std::string const&)' follow
/tmp/ccqckP1I.o:main.cpp:(.text+0x1f8c): undefined reference to `DeleteAllCards(Node*&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x1f9a): undefined reference to `DeleteAllCards(Node*&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x1fa8): undefined reference to `DeleteAllCards(Node*&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x1fb6): undefined reference to `DeleteAllCards(Node*&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x1fc4): undefined reference to `DeleteAllCards(Node*&)'
/tmp/ccqckP1I.o:main.cpp:(.text+0x1fd2): more undefined references to `DeleteAllCards(Node*&)' follow
/usr/lib/gcc/i686-pc-cygwin/4.7.3/../../../../i686-pc-cygwin/bin/ld: /tmp/ccqckP1I.o: bad reloc address 0x1b in section `.text$_ZNSt11char_traitsIcE7compareEPKcS2_j[__ZNSt11char_traitsIcE7compareEPKcS2_j]'
collect2: error: ld returned 1 exit status
4

3 に答える 3

2

次のプロトタイプ(あなたが言及した最初のバリアント)は正しいです:

void Deal(Node *deck,
          Node *hands[],
          int num_hands,
          const std::string &type,
          int num_cards);

たとえば、次のように使用すると:

Node n;
Node* deck = &n;
Node* hands[4];
Deal(deck, hands, 4, "one-at-a-time", 13);

この場合、まだhandsインスタンスを指していない単なるポインタの配列であることに注意してください。Nodeそれらを使用する前に、それらが有効なオブジェクトを指していることを確認してください。

for (int i = 0; i < num_hands; ++i)
    hands[i] = new Node();
于 2013-10-04T20:47:14.773 に答える
0
Node [] *hands

...する必要があります

Node* hands[]

また

Node** hands
于 2013-10-04T20:45:23.497 に答える
0

解決策の1つは、

Deal(Node *deck, Node **hands, int num_hands, const std::string &type, int num_cards)

例のように呼び出すことができます。

于 2013-10-04T20:46:26.243 に答える