C++ 如何在c++;?
我正在尝试从我的主入口RPG.cpp初始化我的游戏引擎。其中包括:C++ 如何在c++;?,c++,static,main,C++,Static,Main,我正在尝试从我的主入口RPG.cpp初始化我的游戏引擎。其中包括: #include "stdafx.h" #include "Engine.h" int _tmain(int argc, _TCHAR* argv[]) { Engine::Go(); return 0; } Engine:Go()是启动游戏引擎的公共方法。但是,它下面有一个错误:“错误:非静态成员引用必须相对于特定对象” 通过我的engine类,让它中的所有内容都是静态的,解决了这个问题,但这本身就是个问
#include "stdafx.h"
#include "Engine.h"
int _tmain(int argc, _TCHAR* argv[])
{
Engine::Go();
return 0;
}
Engine:Go()是启动游戏引擎的公共方法。但是,它下面有一个错误:“错误:非静态成员引用必须相对于特定对象”
通过我的engine类,让它中的所有内容都是静态的,解决了这个问题,但这本身就是个问题。如何绕过此错误而不使用关键字static?创建一个
引擎的实例,并在其上调用Go()
Engine e;
e.Go();
静态
函数基本上是自由函数,可以访问它们所属类的私有
静态
成员。我所说的“自由函数”是指它们不属于某个实例,基本上与普通的C函数类似(除了它们的特殊访问权限)
必须对所属类的实例调用非
静态函数
class Klass {
int i;
static int s_i;
public:
static void static_func() {
// called without an instance of Klass
// s_i is available because it is static
// i is not available here because it is non-static
// (belongs to an instance of Klass)
}
void non_static_func() {
// called on an instance of Klass
// s_i is available here because non_static_func() is a member of Klass
// i is also available here because non_static_func() is called on
// an instance (k) of Klass
}
};
void free_func() {
// s_i and i are both unavailable here because free_func()
// is outside of Klass
}
int main() {
// Klass::static_func() is called without an instance,
// but with the name qualifier Klass:
Klass::static_func();
// Klass::non_static_func() is called with an instance:
Klass k;
k.non_static_func();
// free_func() is called without any instance, and without a name qualifier:
free_func();
}
创建一个
引擎的实例
并对其调用Go()
Engine e;
e.Go();
静态
函数基本上是自由函数,可以访问它们所属类的私有
静态
成员。我所说的“自由函数”是指它们不属于某个实例,基本上与普通的C函数类似(除了它们的特殊访问权限)
必须对所属类的实例调用非静态函数
class Klass {
int i;
static int s_i;
public:
static void static_func() {
// called without an instance of Klass
// s_i is available because it is static
// i is not available here because it is non-static
// (belongs to an instance of Klass)
}
void non_static_func() {
// called on an instance of Klass
// s_i is available here because non_static_func() is a member of Klass
// i is also available here because non_static_func() is called on
// an instance (k) of Klass
}
};
void free_func() {
// s_i and i are both unavailable here because free_func()
// is outside of Klass
}
int main() {
// Klass::static_func() is called without an instance,
// but with the name qualifier Klass:
Klass::static_func();
// Klass::non_static_func() is called with an instance:
Klass k;
k.non_static_func();
// free_func() is called without any instance, and without a name qualifier:
free_func();
}
创建一个
引擎的实例
并对其调用Go()
Engine e;
e.Go();
静态
函数基本上是自由函数,可以访问它们所属类的私有
静态
成员。我所说的“自由函数”是指它们不属于某个实例,基本上与普通的C函数类似(除了它们的特殊访问权限)
必须对所属类的实例调用非静态函数
class Klass {
int i;
static int s_i;
public:
static void static_func() {
// called without an instance of Klass
// s_i is available because it is static
// i is not available here because it is non-static
// (belongs to an instance of Klass)
}
void non_static_func() {
// called on an instance of Klass
// s_i is available here because non_static_func() is a member of Klass
// i is also available here because non_static_func() is called on
// an instance (k) of Klass
}
};
void free_func() {
// s_i and i are both unavailable here because free_func()
// is outside of Klass
}
int main() {
// Klass::static_func() is called without an instance,
// but with the name qualifier Klass:
Klass::static_func();
// Klass::non_static_func() is called with an instance:
Klass k;
k.non_static_func();
// free_func() is called without any instance, and without a name qualifier:
free_func();
}
创建一个
引擎的实例
并对其调用Go()
Engine e;
e.Go();
静态
函数基本上是自由函数,可以访问它们所属类的私有
静态
成员。我所说的“自由函数”是指它们不属于某个实例,基本上与普通的C函数类似(除了它们的特殊访问权限)
必须对所属类的实例调用非静态函数
class Klass {
int i;
static int s_i;
public:
static void static_func() {
// called without an instance of Klass
// s_i is available because it is static
// i is not available here because it is non-static
// (belongs to an instance of Klass)
}
void non_static_func() {
// called on an instance of Klass
// s_i is available here because non_static_func() is a member of Klass
// i is also available here because non_static_func() is called on
// an instance (k) of Klass
}
};
void free_func() {
// s_i and i are both unavailable here because free_func()
// is outside of Klass
}
int main() {
// Klass::static_func() is called without an instance,
// but with the name qualifier Klass:
Klass::static_func();
// Klass::non_static_func() is called with an instance:
Klass k;
k.non_static_func();
// free_func() is called without any instance, and without a name qualifier:
free_func();
}
您必须实际创建
引擎
类的实例
例如:
Engine e;
e.Go();
您必须实际创建
引擎
类的实例
例如:
Engine e;
e.Go();
您必须实际创建
引擎
类的实例
例如:
Engine e;
e.Go();
您必须实际创建
引擎
类的实例
例如:
Engine e;
e.Go();
您可能需要非静态成员函数和
Engine engine;
engine.Go();
静态
成员函数不需要在特定对象实例上调用,但这样它们就不会有隐式的此
指针或非静态
成员变量可访问-它们只能访问类的其他静态
成员。您可能需要非静态成员函数和
Engine engine;
engine.Go();
静态
成员函数不需要在特定对象实例上调用,但这样它们就不会有隐式的此
指针或非静态
成员变量可访问-它们只能访问类的其他静态
成员。您可能需要非静态成员函数和
Engine engine;
engine.Go();
静态
成员函数不需要在特定对象实例上调用,但这样它们就不会有隐式的此
指针或非静态
成员变量可访问-它们只能访问类的其他静态
成员。您可能需要非静态成员函数和
Engine engine;
engine.Go();
static
成员函数不需要在特定的对象实例上调用,但这样它们就不会有隐式的this
指针或非static
成员变量可访问-它们只能访问类的其他static
成员。Wow,这就解释了这一点。我仍然是这方面的新手。谢谢,这就解释了。我仍然是这方面的新手。谢谢,这就解释了。我仍然是这方面的新手。谢谢,这就解释了。我仍然是这方面的新手。谢谢