我無法結束我的for
循環。即使它看起來應該完成,它也會繼續。如何結束通過指針數組的循環
它通過一組指針數組,當最後一個指針返回時NULL
它應該結束。但它仍在繼續。我覺得我錯過了一些相當簡單的事情。任何想法都表示讚賞。
#include "shape.h"
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
shape *getShape();
int main(){
shape *shape[10];
for(int idx = 0; shape[idx] != NULL; ++idx)
{
shape[idx] = getShape();
}
cout << "you made it!";
return (0);
}
你很困惑C和C++。 – wildplasser
getShape是做什麼的?它是否曾經返回NULL值? –
for()'循環不知道'shape []'的大小是10,它只是繼續前進,直到找到一個NULL,如果你沒有放置一個它不會神奇地產生通過它自己。 C字符串是空終止的,數組不是。 – Havenard