这可能是一个愚蠢的问题.我开始一个新的Django项目,正如Document所说,它只包含一个管理页面.我启动服务器并使用访问该页面的Web浏览器.我可以在用户名和密码中输入什么?他们可以在任何地方配置默认的管理员帐户吗?
我知道c#,就像Java一样,将源代码转换为字节码并由VM运行,因为C#案例是CIL存储在汇编中并由CLR执行.开发人员几乎不需要关心变量在堆栈上或堆上的位置(由GC处理)作为c ++,对吧?
他们是否有任何快速而直接的方式来证明变量存储在堆栈上或堆上?例如,如果我告诉某人,引用类型变量存储在堆上,或者本地值类型变量存储在堆栈上(对吗?).我怎样才能明确地表明这一点?在C++中,我可以获取变量的内存地址,并通过VS内存窗口查看存储在堆栈或堆内存中的值.
当我运行下面的代码时,我有一个关于使用关键字 auto 的问题:
auto i_num = {1};
printf("%x", i_num);//61fecc
return 0;
Run Code Online (Sandbox Code Playgroud)
我认为它与下面的相同,但不是:
int i_num = {1};
printf("%x", i_num);//1
return 0;
Run Code Online (Sandbox Code Playgroud)
谁能给我解释一下这个区别吗?看来 auto i_num 和 int i_num 定义了不同的东西。
该代码段是从维基百科。
void WriteToFile(const std::string& message) {
// |mutex| is to protect access to |file| (which is shared across threads).
static std::mutex mutex;
// Lock |mutex| before accessing |file|.
std::lock_guard<std::mutex> lock(mutex);
// Try to open file.
std::ofstream file("example.txt");
if (!file.is_open()) {
throw std::runtime_error("unable to open file");
}
// Write |message| to |file|.
file << message << std::endl;
// |file| will be closed first when leaving scope (regardless of exception)
// mutex will be unlocked second (from lock destructor) when …Run Code Online (Sandbox Code Playgroud) 请参阅此页面并转到示例.这是关于使用的演示
struct type {
type() :i(3) {}
void m1(int v) const {
// this->i = v; // compile error: this is a pointer to const
const_cast<type*>(this)->i = v; // OK as long as the type object isn't const
}
int i;
};
Run Code Online (Sandbox Code Playgroud)
const这里意味着m1无法修改类型的成员变量.我不明白为什么const_cast会修改常量性这个.我的意思是,这个指针指向当前类型对象,而不是i本身.
为什么不:
const_cast<int>((this)->i) = v;
Run Code Online (Sandbox Code Playgroud)
我可以说当一个成员函数使用const限定符时,整个对象和所有成员变量都变为const吗?为什么这是const指针?