我正在观察编译器警告,其中显示“信息 - 范围操作员可以访问静态类成员”。使用inFile.seekg(0,inFile.end)和inFile.seekg(0,inFile.beg)时会发出警告
警告究竟意味着什么 - 我用Google搜索但却找不到。
/*Gets the size of file in bytes*/
inFile.seekg(0, inFile.end);
lengthOfFile = (int)inFile.tellg();
/*Resets the pointer to beginning of File*/
inFile.seekg(0, inFile.beg);
答案 0 :(得分:4)
我认为警告是inFile.beg
和inFile.end
,它们是std::ios_base
的静态成员。因此,您可能希望将其称为std::ios_base::beg
和std::ios_base::end
。
访问静态成员的两种方式都是合法的,但我更喜欢作用域操作符版本,因为它不会留下歧义。
答案 1 :(得分:2)
您可以使用对象中的成员访问语法或使用类作用域运算符来访问struct Foo
{
static int bar;
};
int Foo::bar = 0;
int main()
{
Foo f;
f.bar = 10; // Access Foo::bar using the member access syntax from f
Foo::bar = 20; // Access Foo::bar using the class scope operator.
}
成员变量。
示例:
Foo::bar
两者都是访问inFile.seekg(0, inFile.beg);
inFile.seekg(0, std::ios_base::beg);
的有效方法。显然,编译器试图提供帮助。它让你知道你可以使用类范围操作符访问该对象。
在您的情况下,您可以使用以下两种形式之一:
var viewStartDate = getViewFormattedDate($('#calendar').fullCalendar('getView').start._d);
var viewEndDate = getViewFormattedDate($('#calendar').fullCalendar('getView').end._d);
console.log(viewStartDate+"---"+viewEndDate);