这是我之前的问题的后续问题:为什么成员函数返回非静态数据成员而不是核心常量表达式?
该问题中提到的示例的简化版本是:
struct S {
const bool x = true;
constexpr bool f() { return x; }
};
int main() {
S s{};
static_assert(s.f()); // error: 's' is not a constexpr;
}
Run Code Online (Sandbox Code Playgroud)
标准中适用的措辞是 N4861:[expr.const]/(5.1):
表达式
E是核心常量表达式E,除非 的计算遵循抽象机 ([intro.execution]) 的规则,将计算以下其中一项:
- (5.1) ([expr.prim.this]),但作为 的一部分进行求值的函数 ([dcl.constexpr])
this除外;constexprE
据我可以解析,表达式E是并且s.f()它的计算结果是返回一个非静态成员。但这属于“例外”部分:成员函数是 constexpr 函数,它作为. 如果我解析正确,我期望得到常量表达式并且断言成功。thiss.f()this->xs.S::f()s.f()s.f()
s但是,该项目符号并未指定必须是常量表达式的要求。我不明白为什么声明sasconstexpr会编译程序,即使没有在此项目符号中定义的s要求constexpr。
我只是在我的示例中应用了措辞(5.1),但我看不到 …
我$.each在li标签上执行.li标签包含不同的标签.如何从当前迭代中访问标签?
示例代码:
jQuery的
$('.list li').each(function () {
// I tried, but didnt work: $(this).filter(".aside h4 a").html("Hello");
$(this)._HERE TRYING TO ACCESS CHILDREN_.html("Hello");
});
Run Code Online (Sandbox Code Playgroud)
HTML
<ul class="list">
<li>
<div class="aside right">
<h4><a href="#">I want to change this text on each iteration</a></h4>
</li>
<li>
<div class="aside right">
<h4><a href="#">I want to change this text on each iteration</a></h4>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud) 我目前有链接的jQuery代码.单击选定的链接时,将打开对话框.
$('.dialog_link_add').click(function(){
var row_id = $(this).parent().parent().attr('id');
return false;
}
Run Code Online (Sandbox Code Playgroud)
因为对话框总是使窗口滚动到顶部(在Internet Explorer中),我通过使用纯JavaScript并使用旧的方式实现方法找到了解决方案.
onclick="function_call(this);return false;"
Run Code Online (Sandbox Code Playgroud)
......但它不起作用.我现在如何发送"this"参数等于jQuery $(this)?
有人可以解释为什么你不能在私人方法中使用'this'吗?
或者也许我读错了; 它列出了一个私有方法,并说"不能使用此操作符"?
$ this-> id和$ id有什么区别.
class Test{
public $id;
function Test(){
$this->id = 1;
}
}
Run Code Online (Sandbox Code Playgroud)
===
class Test{
public $id;
function test(){
$id = 1;
}
}
Run Code Online (Sandbox Code Playgroud)
如何从其他类中获取变量?
class TestA{
public $test;
function TestA(){
$this->test = new Test();
echo $this->test->id;
}
}
Run Code Online (Sandbox Code Playgroud) 有一种简单的方法可以在c ++中抛出自定义空指针异常吗?我的想法是重新定义this指针,但它有3个问题:
thisthrows标准Acces Violation ExceptionVisual Studio将此显示为InteliSense错误(可编译)(不知道其他编译器做了什么)
#include <iostream>
#define this (this != nullptr ? (*this) : throw "NullPointerException")
class Obj
{
public:
int x;
void Add(const Obj& obj)
{
this.x += obj.x; // throws "NullPointerException"
//x = obj.x; // throws Access Violation Exception
}
};
void main()
{
Obj *o = new Obj();
Obj *o2 = nullptr;
try
{
(*o2).Add(*o);
}
catch (char *exception)
{
std::cout << exception;
}
getchar();
}
Run Code Online (Sandbox Code Playgroud)想知道两者之间是否存在差异:
public Bee (double weight)
{
this.weight = weight;
Run Code Online (Sandbox Code Playgroud)
和
public Bee (double weight)
{
weight = this.weight;
Run Code Online (Sandbox Code Playgroud)
如果你切换等于"="符号的左右两边,它会改变含义吗?
(设置属性值)与以下内容之间是否有任何区别:
var obj = {
getData: function ()
{
this.age = 34 //notice this
}
}
obj.getData();
alert(obj.age) //34
Run Code Online (Sandbox Code Playgroud)
VS
var obj = {
getData: function ()
{
obj.age = 34 //notice obj
}
}
obj.getData();
alert(obj.age) //34
Run Code Online (Sandbox Code Playgroud)
我什么时候应该使用?
首先我知道这一定很简单,我一直在尝试在Stackoverflow.com和Google上阅读类似的问题,但我仍然无法让我的程序运行.
我很快写了一篇关于我的程序试图做的摘要:
public class One{
public One(){
Two t = new Two(this);
}
public void doSomething(){
sout("HERE");
}
public static void main(String[] args){
One o = new One()
Two t = new Two(o);
}
}
public class Two{
public Two(One o){
One o = o;
o.doSomething();
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行程序时,我从方法调用o.doSomething()得到一个NullPointerException.我已经尝试了一段时间来解决它,但我很难过.如果有人能够快速告诉我修复它会非常感激.
这两种类型有什么不同吗?
public class MyClass{
String name;
public MyClass(String nn){
this.name = nn;
name = nn;
}
}
Run Code Online (Sandbox Code Playgroud)