我正在编写一个链表,我想要一个struct的析构函数(一个Node结构)来简单地删除它自己,并且没有任何副作用.我希望我的列表的析构函数迭代地自己调用Node析构函数(临时存储下一个节点),如下所示:
//my list class has first and last pointers
//and my nodes each have a pointer to the previous and next
//node
DoublyLinkedList::~DoublyLinkedList
{
Node *temp = first();
while (temp->next() != NULL)
{
delete temp;
temp = temp->next();
}
}
Run Code Online (Sandbox Code Playgroud)
所以这将是我的Node析构函数:
Node::~Node
{
delete this;
}
Run Code Online (Sandbox Code Playgroud)
这是否可以接受,特别是在这种情况下?
使用:Nodejs + aws-amplify
从AWS Amplify文档中,但他们登录后我还没有成功检查过用户。
index.js
const Amplify = require('aws-amplify');
global.fetch = require('node-fetch'); // [source](https://github.com/aws-amplify/amplify-js/issues/876)
global.navigator = {};
Amplify.default.Auth({
identityPoolId: IDENTITYPOOLID,
region: REGION,
userPoolId: USERPOOLID,
userPoolWebClientId: APPCLIENTID,
});
Amplify.Auth.signIn(username, password).then(user => {
localstorage.set('user', JSON.stringify(user));
console.log(user); // "cognitoUser" object
return Amplify.Auth.getSession();
}).then(session => {
console.log(session); // "CognitoSession" object
}).catch(err => {
console.log(err);
});
// PROBLEM
Amplify.Auth.getSession().then(session => {
console.log(session);
}).catch(err => {
console.log(err); // PRINT: no current user
});
Run Code Online (Sandbox Code Playgroud)
除非包装在内,否则我似乎无法获得用户会话Auth.signIn
。我尝试使用;
// Problem
let userObj = JSON.parse(localstorage.get('use'));
Amplify.Auth.userSession(userObj).then(data …
Run Code Online (Sandbox Code Playgroud) 免责声明:我是一名正在学习编程的非专业人士.从未参与过项目,也没有写过超过500行的文章.
我的问题是:防御性编程是否违反了"不要重复自己"的原则?假设我对防御性编程的定义是正确的(让调用函数验证输入而不是相反),这对你的代码不会有害吗?
例如,这很糟糕:
int foo(int bar)
{
if (bar != /*condition*/)
{
//code, assert, return, etc.
}
}
int main()
{
int input = 10;
foo(input); //doesn't the extra logic
foo(input); //and potentially extra calls
foo(input); //work against you?
}
Run Code Online (Sandbox Code Playgroud)
与此相比:
int main()
{
if (input == /*condition*/)
{
foo(input);
foo(input);
foo(input);
}
}
Run Code Online (Sandbox Code Playgroud)
再说一次,作为一个外行人,我不知道有多少简单的逻辑陈述对你来说就性能而言是多少,但对于程序或灵魂而言,防御性编程肯定不好.
我的步骤:
我最近根据指令编写了一个基于节点的堆栈类(代码之前的注释中的规范,取自论坛帖子).我被告知要在这里发布它以供SO社区的一位更友好的成员审阅,所以在这里.为简单起见:我将定义与实现相结合.我知道何时使用头文件=)
主要是,我想知道我对删除的使用是否合理.在使用析构函数时,我仍然不确定自己; 规范使它听起来像我应该删除节点的唯一时间应该是在流行期间,其他任何东西是不安全的.我也不明白这里使用的是复制构造函数/赋值构造函数.
无论如何,关于代码的任何错误或评论都会很棒.
/*stack class
Background: the specs for this are, verbatim:
"Write a node-based stack class smile.gif
The stack is one of the most fundamental data structures used in computer science.
A stack has three basic operations:
push(value) - puts a value on the top of the stack
pop() - removes and returns the value that's on the top of the stack
peek() - return (but does not remove) the value off the top of the stack
Before …
Run Code Online (Sandbox Code Playgroud) 我的 cognito 资源上有一个用于预注册触发器的 Lambda 触发器。
我遇到套接字超时,但没有找到太多相关文档
{
"err": {
"code": "UnexpectedLambdaException",
"name": "UnexpectedLambdaException",
"message": "arn:aws:lambda:region-arn:function:confirm failed with error Socket timeout while invoking Lambda function."
}
}
Run Code Online (Sandbox Code Playgroud)
我的资源定义如下:
"ConfirmPermission" : {
"Type" : "AWS::Lambda::Permission",
"Properties" : {
"Action" : "lambda:InvokeFunction",
"FunctionName" : { "Fn::GetAtt" : [ "confirm", "Arn" ] },
"Principal" : "cognito-idp.amazonaws.com",
"SourceArn" : { "Fn::GetAtt" : [ "Auth", "Arn" ] }
}
},
"confirm" : {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.confirm",
"Runtime": "nodejs8.10",
"CodeUri": "./src",
"FunctionName": …
Run Code Online (Sandbox Code Playgroud) amazon-web-services amazon-cognito aws-lambda amazon-cognito-triggers
我有一个小缩略图库.当我将鼠标指针放在缩略图图像上时,我希望在屏幕右上角的div中弹出一个完整大小的图像.我已经看到这只使用CSS完成,我想沿着那条路走下去,而不是在可能的情况下使用javascript.
我是一个业余爱好者控制台C++开发人员.我使用过指针,数组,std :: vectors,std :: strings,类和几个数据结构,包括堆栈和二叉树.我在线性代数和几何方面有一些经验,并且了解物理学的基础知识.我没有win32,QT,openGL,DX9,OGRE等经验.我还在学习OOP中更有价值的部分,比如多态.
我开始使用C++作为第一语言,并且没有其他语言的经验.我可以使用C,但我需要习惯于操作char*和常规数组(而不是初始化变量).
我的问题是,根据我的经验,我应该何时进入GUI应用程序/游戏应用程序的开发?我是否需要在某些数学领域更加坚定自己,适应win32,习惯SDK?
如果这个问题太主观,你不能轻易提出建议,那么你什么时候进入GUI /游戏开发,你采取了哪些措施让自己感到舒服?
编辑它会使它受到影响.还有其他人有什么意见吗?
namespace A
{
#include <iostream>
};
int main(){
A::std::cout << "\nSample";
return 0;
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
为什么引用在C++中不可重定位
我试图或多或少交换两个引用变量(作为实践,我可以交换实际变量).我尝试通过创建一个临时变量并使其中一个引用与另一个相等来做到这一点,但这被编译器击落了.这是一个例子:
void Foo()
{
//code
int& ref1 = a;
int& ref2 = b;
int temp;
temp = ref1;
ref1 = ref2;
ref2 = temp;
//or, better yet
std::swap(ref1, ref2);
}
Run Code Online (Sandbox Code Playgroud)
我收到了一个错误,并查看了faq lite.它详细说明了它们无法重新安装,但没有解释原因.为什么?
这是Faq Lite的链接供参考(<---,得到它?).
c++ ×5
async-await ×1
asynchronous ×1
aws-amplify ×1
aws-lambda ×1
css ×1
destructor ×1
dry ×1
linked-list ×1
namespaces ×1
node.js ×1
popup ×1
promise ×1
reference ×1
sdk ×1
stack ×1
std ×1
this ×1
xhtml ×1