ページ 11

Static members

Posted: 2012年10月09日(火) 18:02
by Static members
正しく動作させるためには、あとどうすれば良いでしょうか?

Write a class UniqueID such that each instance of this class has a unique identifier (the type of this identifier should be int). The identifier for the first instance of UniqueID should be one, then each new instance will have an identifier with the value one plus the identifier of the previously created object. The identifier can be accessed with the method getID().

Define the class UniqueID in files named UniqueID.h and UniqueID.cpp. To test your code create a file testUniqueID.cpp and type the code below:

コード:

// testUniqueID.cpp

#include <cassert> // for assert()

// COMPLETE: include the proper header

int main(void) {
  UniqueID uid1;
  assert(uid1.getID() == 1);
  
  UniqueID uid2;
  assert(uid2.getID() == 2);
  
  UniqueID uid3;
  assert(uid3.getID() == 3);
  
  return 0;
}

Re: Static members

Posted: 2012年10月09日(火) 18:15
by softya(ソフト屋)
当掲示板は課題の丸投げは禁止させて頂いています。
かならず、ご自分で書いたコードも投稿なさってください。
どうしても分からない時は解き方についてご質問ください。

詳しくは、こちらの方をご覧ください。
「An array-based stack • C言語交流フォーラム ~ mixC++ ~」
http://dixq.net/forum/viewtopic.php?f=3&t=11637