添加此代码:
AddType application/x-httpd-php .php 后
...
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
Run Code Online (Sandbox Code Playgroud)
要
C:\Apache24\bin\httpd.conf
下载我的系统上的所有PHP页面,而不是渲染。
在此之前,PHP 页面被解析为原始文本。
需要帮助!
为什么我会收到此错误:
Uncaught TypeError: Symbol.prototype [ @@toPrimitive ] requires that 'this' be a Symbol
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时?
3 == Symbol.prototype
Run Code Online (Sandbox Code Playgroud)
我仍在尝试自己找出原因,到目前为止使用一个try-catch块来按住它一段时间,但我想要一个错误的原因。
所以,我尝试有一天,当我在堆栈溢出碰到这个问题就来了,并得到了好奇:在Javascript中数组的最大尺寸(在JavaScript中数组的最大大小).
问题是,JavaScript中数组的最大深度是多少?
深度我的意思是你可以在一个数组中嵌入一个数组,直到JavaScript放弃?
[1] // Depth Level: 1
[1, [2]] // Depth Level: 2
[1, [2, [3]]] // Depth Level: 3
[1, [...]] // Depth Level: x?
Run Code Online (Sandbox Code Playgroud)
它是否依赖于机器,是否基于编译器?
不,我不确定这是否有任何实际用途,但它仍然是我很好奇的东西.
这里的基本问题是我如何知道何时使用和
每个人之间的关键区别是什么:
Number.parseInt方法(或只是parseInt),Number.parseFloat方法(或只是parseFloat),Number() 功能(或类?),+操作员用于将JavaScript值(主要是String's)转换为数字.
特别是因为所有这些都给出了类似的值并且可以转换String为它的Number表示:
Number.parseInt("2") // returns 2
Number.parseFloat("2") // returns 2
Number("2") // returns 2
+"2" // returns 2
/* Plus a few more methods... */
eval("2") // returns 2
JSON.parse("2") // returns 2
Run Code Online (Sandbox Code Playgroud) 所以这里有一些C++开发人员的难题.
我有一个String我正在使用的自定义类,它应该教会我如何熟悉类和其他一些C++特性,这个类有一个value属性,用于跟踪它的原始值(即a std::string).
但是这里有一个问题,我已经定义了多种方法来创建这个类的对象.其中2个我完全理解:
String stringA = "Hello, World!";
String stringB = String("Hello, World!");
Run Code Online (Sandbox Code Playgroud)
但是最后一个有点棘手,因为它应该能够使用无限的一组参数(理论上).
String stringC = String("Hello,", ' ', "World!");
Run Code Online (Sandbox Code Playgroud)
但是当我访问这些字符串的原始值时,最后一个似乎会出错并返回(尽我最大的调试工作)没有任何内容,乱码文本或只是给出的部分参数.
stringA.valueOf(); // -> Hello, World!
stringB.valueOf(); // -> Hello, World!
stringC.valueOf(); // -> Hello,
Run Code Online (Sandbox Code Playgroud)
现在,这是一个我一直在努力的挑战,特别是作为一名潜入C++的JavaScript开发人员.我知道这两种语言根本不同,但我认为逻辑上应该有前者的一些特征可以在某种程度上适用于后者(例如可变参数).
对于任何可以帮助解决这个问题的人,并向我解释我缺少的东西(或者为什么我的代码很糟糕),你就是绝对的冠军.太棒了.
#include <iostream>
/* Let's assume there's a `stringify` function that converts any value to `std::string` */
class String {
private:
std::string value;
public:
template <typename data>
String(data arg) { this -> value += arg; }
template …Run Code Online (Sandbox Code Playgroud) 假设我有以下代码:
bool isString(char* arg) { return true; }
bool isString(const char* arg) { return true; }
bool isString(std::string arg) { return true; }
// Any other type...
template <typename type> bool isString(type arg) { return false; }
Run Code Online (Sandbox Code Playgroud)
问题是,C++是否允许任何合理的方式将下面的语法缩短为类似于下面的概念(语法简写/糖):
// Could be `char*`, `const char*` or `std::string` here.
bool isString([char*, const char*, std::string] arg) { return true; }
// Any other type...
template <typename type> bool isString(type arg) { return false; }
Run Code Online (Sandbox Code Playgroud)
这里给出的示例不一定用于检测字符串,而是用于解释多行代码专用于重载函数的问题.
想象一下,如果我必须测试100多种数据类型是否有效,我会很快想要一种更短的编码方式,而不是输入所有100个重载函数
当然,这种句法简写的缺点是arg无法区分数据类型(与标准函数重载不同).
想象一下这个假设情景.
我创建了两个类Boolean,String它们彼此独立(包括它们各自的方法和属性).
我需要一个这样的类(Boolean)来创建一个新的,String当它中的某个方法被调用(让我们说toString)时,另一个(String)Boolean在isEmpty调用it()中的方法时创建一个新的.
这是代码:
消息代码1
#include <string.h>
class Boolean;
class String;
class Boolean {
bool value = false;
public:
Boolean(bool value) { this -> value = value; }
String toString() { return String(value ? "true" : "false"); }
};
class String {
char* value;
public:
String(const char* value) { this -> value = strdup(value); }
Boolean isEmpty() { return Boolean(!strcmp(value, "")); }
};
Run Code Online (Sandbox Code Playgroud)
当然,这不起作用,因为在 …
所以最近我正在使用创建我自己的C++类的概念来表示通用数据(例如字符串,数字和数组).
到目前为止,我在这方面的进展一直很好(如下所示:https://github.com/LapysDev/LapysCPP).
除了一个故障.对于我的生活,在创建String具有可变数量参数的类对象时,我无法弄清楚为什么下面的代码会出错.
#include <iostream>
#include <sstream>
#include <string.h>
// Make a new C-style string (or stringify a value).
char* stringify(char character) {
std::string stream = static_cast<std::ostringstream*>(&(std::ostringstream() << character)) -> str();
char* string = new char[stream.size() + 1];
strcpy(string, stream.c_str());
return string;
}
template <typename data> char* stringify(data string) { return strdup(std::string(string).c_str()); }
char* globalString = stringify("");
class String {
public:
char* value = stringify("");
String() {}
template <typename data>
String(data value) {
strcat(globalString, …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用 C++ 类创建代码接口。
测试中出现的一个令人困惑的事情是重载赋值运算符。看看下面的代码:
struct my_object {
// This doesn't work. :(
friend int& operator =(int& variable, my_object object)
{ variable = object.value; return variable; }
// This works, but `int value; value <<= my_object{};`
// for `int value; value = my_object{};` doesn't seem clean...
friend int& operator <<=(int& variable, my_object object)
{ variable = object.value; return variable; }
};
Run Code Online (Sandbox Code Playgroud)
我的困惑是:
第一个重载不会编译并将此错误记录到控制台终端。
'friend int& operator =(int&, my_object)' must be a nonstatic member function
Run Code Online (Sandbox Code Playgroud)
但是,第二个重载编译时没有任何错误(或警告),尽管与第一个重载几乎相同。
为什么第一个运算符重载无效而第二个运算符重载似乎很好(至少对于GCC 6.3.0编译器来说)?
所以我一直在玩C/C++中的数组,试图创建可以动态添加和删除元素的数组.
当然,我认为C语言中的灵活数组成员特征是合适的方式.所以我开始尝试,因为下面的代码显示:
#include <cstdio> // printing stuff
#include <stdlib.h> // memory allocation stuff
// The array type
template <typename structType>
struct Array {
private:
// The structure containing the F.A.M.
struct ArrayStructure { size_t length = 0; structType array[]; }
*arrayStructurePointer, arrayStructure;
constexpr inline static void add() {}
public:
// Constructor
template <typename... types, typename = structType>
explicit Array(types... elements) {
this -> arrayStructurePointer =
(ArrayStructure*) malloc(sizeof(structType));
this -> arrayStructurePointer = &(this -> arrayStructure);
this -> add(elements...);
}
// …Run Code Online (Sandbox Code Playgroud) 假设这样的代码:
#include <stdlib.h>
int main(int argc, char* argv[]) {
int value = 42;
void* pointer = (void*) &value;
// Free stack memory
free(pointer);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
此代码导致未定义的行为,因为它尝试在堆栈上取消分配内存。
但是我在想;每次释放指针之前如何重新分配一个指针。
#include <stdlib.h>
int main(int argc, char* argv[]) {
int value = 42;
void* pointer = (void*) &value;
// Allocate pointer on heap, then free memory
pointer = realloc(pointer, sizeof pointer);
free(pointer);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的假设是,这会将指针发送到堆内存,因此可以适当地释放它。
所有这些都是在程序员不知道在哪个内存(堆或堆栈)上指定了指针的情况下进行的(此时,程序的设计存在疑问,但我不会提出疑问)。
这是确保内存正确释放的安全方法,还是不适当的方法并在内存中创建了垃圾对象?
只是想知道scan()C++中是否有可能有一个函数(比如或者其他)做与std::cin语法相同的事情?
std::cin >> data; // or
scan(data);
Run Code Online (Sandbox Code Playgroud) 有没有办法(常规或没有)从函数中选择多个指定的返回类型.例如:
/* Concept code... */
class var {
public:
union {
bool _bool;
int _int;
char* _char_pointer;
} primitive_value;
std::string type;
var(bool arg) { primitive_value._bool = arg; type = "bool"; }
var(int arg) { primitive_value._int = arg; type = "int"; }
var(char* arg) { primitive_value._char_pointer = arg; type = "char*"; }
// Function/ method that could return `bool`, `int` or `char*`
<bool, int, char*> valueOf() const {
if (type == "bool") return primitive_value._bool;
else if (type == "int") return primitive_value._int; …Run Code Online (Sandbox Code Playgroud) c++ ×9
javascript ×3
apache ×1
arrays ×1
c++17 ×1
function ×1
methods ×1
numbers ×1
overloading ×1
php ×1