this

node - this.func() is not a function

佐手、 提交于 2021-01-27 19:31:32
问题 function Job(name, cronString, task) { "use strict"; this.name = name; this.cronString = cronString; this.isReady = false; this.task = task; } Job.prototype.performTask = (db, winston) => { "use strict"; const Promise = require("bluebird"); let that = this; return new Promise((resolve, reject) => { let output = ""; let success = true; try { output = that.task(); } catch(error) { success = false; reject(error); } if(success) { resolve(output); } }); }; module.exports = Job; Javascript newbie

Template method accesses forward declared class fails to compile only without this pointer

99封情书 提交于 2021-01-27 06:56:38
问题 When I compile the following code with the latest Visual Studio, it success to compile. class C; class T { public: template<typename A> void f(); private: C* c; }; int main() { T t; t.f<int>(); } template<typename A> void T::f() { this->c->g(); } class C { public: void g() {} }; But when I remove this-> from this->c->g() , compilation fails with C2027: use of undefined type 'C' . When I make the method f non-template, it fails to compile no matter this-> presents or not, so I think it's

Template method accesses forward declared class fails to compile only without this pointer

徘徊边缘 提交于 2021-01-27 06:54:27
问题 When I compile the following code with the latest Visual Studio, it success to compile. class C; class T { public: template<typename A> void f(); private: C* c; }; int main() { T t; t.f<int>(); } template<typename A> void T::f() { this->c->g(); } class C { public: void g() {} }; But when I remove this-> from this->c->g() , compilation fails with C2027: use of undefined type 'C' . When I make the method f non-template, it fails to compile no matter this-> presents or not, so I think it's

Java this用法

走远了吗. 提交于 2021-01-19 05:47:22
his在JAVA中所代表的意思是当前类中的意思. 明确引用的是本类中的属性. 1. 在构造方法或是set方法中初始化类中的属性. class AA{ String name; public AA(String name){ this.name=name; //如果不写this那肯定出错编译都通不过. } } 2. this用在构造方法中,调用本类中的构造方法. class AA { String name; public AA(){ System.out.println("1无参构造....."); } public AA(String name){ this(); this.name=name; System.out.println("2有参构造....."+name); } public static void main(String[] args) { AA a = new AA("author"); } } 3. 代表调用对象本身. class AA { String name; public AA(){ System.out.println("1无参构造....."); System.out.println(this); // 打印的是对象a的内存地址. } public void play(){ System.out.println("游戏人生........"); }

copy-capturing this with C++ lambdas

ぐ巨炮叔叔 提交于 2020-12-27 07:14:47
问题 Reading up on lambdas, I tried understanding them capturing this and *this . I wrote a small test: #include <iostream> #include <functional> using namespace std; struct A { int x = 0; function<int(void)> get_x_cpy = [=, this]() { return x++; }; function<int(void)> get_x_ref = [&, this]() { return x++; }; }; int main() { A a; cout << a.get_x_cpy() << a.get_x_cpy() << a.get_x_ref() << a.get_x_ref() << '\n'; } and, expecting the get_x_cpy() to make a copy of a I expected to see 0001 or 0101

copy-capturing this with C++ lambdas

亡梦爱人 提交于 2020-12-27 07:13:49
问题 Reading up on lambdas, I tried understanding them capturing this and *this . I wrote a small test: #include <iostream> #include <functional> using namespace std; struct A { int x = 0; function<int(void)> get_x_cpy = [=, this]() { return x++; }; function<int(void)> get_x_ref = [&, this]() { return x++; }; }; int main() { A a; cout << a.get_x_cpy() << a.get_x_cpy() << a.get_x_ref() << a.get_x_ref() << '\n'; } and, expecting the get_x_cpy() to make a copy of a I expected to see 0001 or 0101

copy-capturing this with C++ lambdas

非 Y 不嫁゛ 提交于 2020-12-27 07:12:32
问题 Reading up on lambdas, I tried understanding them capturing this and *this . I wrote a small test: #include <iostream> #include <functional> using namespace std; struct A { int x = 0; function<int(void)> get_x_cpy = [=, this]() { return x++; }; function<int(void)> get_x_ref = [&, this]() { return x++; }; }; int main() { A a; cout << a.get_x_cpy() << a.get_x_cpy() << a.get_x_ref() << a.get_x_ref() << '\n'; } and, expecting the get_x_cpy() to make a copy of a I expected to see 0001 or 0101

copy-capturing this with C++ lambdas

China☆狼群 提交于 2020-12-27 07:12:32
问题 Reading up on lambdas, I tried understanding them capturing this and *this . I wrote a small test: #include <iostream> #include <functional> using namespace std; struct A { int x = 0; function<int(void)> get_x_cpy = [=, this]() { return x++; }; function<int(void)> get_x_ref = [&, this]() { return x++; }; }; int main() { A a; cout << a.get_x_cpy() << a.get_x_cpy() << a.get_x_ref() << a.get_x_ref() << '\n'; } and, expecting the get_x_cpy() to make a copy of a I expected to see 0001 or 0101