2017-07-17 135 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