これを正しく宣言していますか?新しい長い配列を宣言するC++
string regular = "TEST";
long[] cipher = new long[regular.length()];
このコンパイルエラーを取得:expected unqualified-id before '[' token
これを正しく宣言していますか?新しい長い配列を宣言するC++
string regular = "TEST";
long[] cipher = new long[regular.length()];
このコンパイルエラーを取得:expected unqualified-id before '[' token
new
式はポインタを返しますので、あなたのcipher
は1でなければなりません。
long *cipher = new long[regular.length()];
しかし、生の配列を使用するとエラーが発生しやすくなります。代わりにstd::vector
を代入することを検討してください。
std::vector<long> cipher(regular.length());
'{regular.length()} 'で' std :: vector'を初期化しないと、イニシャライザリストコンストラクタを使用し、単一の要素( 'regular.length()')ではなく、 OPが望むように 'regular.length()'要素の量でそれを構築しますか? –
@AlgirdasPreidžius - あなたは正しいですか?ここでブレースの初期化を使用することの副作用。私は正しいc'torが呼ばれたことを確認するために答えを更新しました。 – StoryTeller
配列はポインタではありません。ポインタは配列ではありません。 – molbdnilo
Java構文はC++ではありません。 –