2017-07-17 62 views
-1

好吧,所以我想了解int i(row)和j(col)在這組代碼中的含義,它是否將我設置爲行中的值?我(排)和j(排)是什麼意思?

for(int i(row); i < row + height; ++i) 
{ 
    // Cycle through cols 
    for(int j(col); j < col + width; ++j) 
    { 
     // Change the value at position (i, j) to the fillChar 
     board[i][j] = fillChar; 
    } 
} 
+0

是的,認爲它是調用int的「構造函數」。 –

+0

@brian所以我=行? – poppy

+0

是的,確切地說。 'int'也有一個默認的構造函數:'int i {}; //我是0'。 –

回答

1

class非/ struct類型C++(例如本徵/「原始」類型intlong等)do not have constructors,但是它們確實具有初始化語法看起來相同作爲構造呼叫。

舉個例子,調用類型的構造是這樣的:

my_class myClassInstance(myClassConstructorArgument); 

同樣,使用int的初始化看起來是這樣的:

int myInt(myInitialValue); 

所以你的情況,for(int i(row); ...是與for(int i = row; ...相同。

There is a third syntax that uses curly braces too

int x = 1; 
int y(2); 
int z{3}; 

cout << x << " " << y << " " << z << endl; 

給出輸出1 2 3