我只是好奇C++ 的差异::和什么->?
目前正在学习C++,因为我想用c ++学习openGL和openGL中的大量教程,所以我会选择有很多教程的语言:)
在java或者C#如果要调用函数或保留函数,只需使用".".比如说text1.getText(); 如果你C++想把它转换成那样的话text1->getText()?什么叫他们?标题不合适.如果->等于"." 在java那么有什么用"::"的?我相信有很多问题像我一样,但我不知道该怎么称呼他们所以我无法获得准确的信息.顺便说一句,我发现这个::想法在使用sfml时.
这是一个例子
if (event.type == sf::Event::Closed)
{
// end the program
running = false;
}
else if (event.type == sf::Event::Resized)
{
// adjust the viewport when the window is resized
glViewport(0, 0, event.size.width, event.size.height);
}
void renderingThread(sf::Window* window)
{
// activate the window's context
window->setActive(true);
// the rendering loop
while (window->isOpen())
{
// draw...
// end the current frame -- this is a rendering function
(it requires the context to be active)
window->display();
}
}
Run Code Online (Sandbox Code Playgroud)
窗口使用 - > sf使用 ::
Nie*_*jes 11
::是作用域解析运算符,用于引用静态类成员和名称空间元素.
->是间接引用运算符,用于引用实例指针上的成员方法和字段.
.是直接引用运算符,用于引用实例上的成员方法和字段.
由于Java没有真正的指针,因此它对间接引用运算符没有用处.