0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

vectorのsize()の型の注意!!!

Last updated at Posted at 2020-09-06

競プロをしていて、

vector<int> v;
int ans;
//処理
ans=max(v.size(),ans); //error🥺🥺🥺

の様に書いたらコンパイラに怒られたので備忘録として。(初心者がバレる)

どうやら v.size()unsigned long型らしい。
(補足:コメントで、戻り値の型は処理系依存であるとのご指摘をいただきました。)
max()の第一引数と第二引数の型が違うと怒られてしまった。

ans=max((int)v.size(),ans); //error🥺🥺🥺

の様にキャストして書きましょう!(あくまでも競プロでのお話です)
、、、というお話。

0
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?