keyword

Is it legal to redefine a C++ keyword?

自作多情 提交于 2019-11-26 07:46:10
问题 In this article from Guru of the week, it is said: It is illegal to #define a reserved word. Is this true? I can’t find anything in the norm, and I have already seen programmers redefining new, for instance. 回答1: 17.4.3.1.1 Macro names [lib.macro.names] 1 Each name defined as a macro in a header is reserved to the implementation for any use if the translation unit includes the header.164) 2 A translation unit that includes a header shall not contain any macros that define names declared or

How to add builtin functions

霸气de小男生 提交于 2019-11-26 06:48:22
问题 I am new to python programming. How can I add new built-in functions and keywords to python interpreter using C or C++? 回答1: In short, it is technically possible to add things to Python's builtins † , but it is almost never necessary (and generally considered a very bad idea). In longer, it's obviously possible to modify Python's source and add new builtins, keywords, etc… But the process for doing that is a bit out of the scope of the question as it stands. If you'd like more detail on how

Is there an ANSI SQL alternative to the MYSQL LIMIT keyword?

旧城冷巷雨未停 提交于 2019-11-26 04:23:56
问题 Is there an ANSI SQL alternative to the MYSQL LIMIT keyword? The LIMIT keyword limits the number of rows returned by a SELECT e.g: SELECT * FROM People WHERE Age > 18 LIMIT 2; returns 2 rows. SELECT * FROM People WHERE Age > 18 LIMIT 10, 2; returns 2 rows after the first 10. 回答1: this shows the different ways: -- DB2 select * from table fetch first 10 rows only -- Informix select first 10 * from table -- Microsoft SQL Server and Access select top 10 * from table -- MySQL and PostgreSQL select

What does “default” mean after a class' function declaration?

廉价感情. 提交于 2019-11-26 03:47:55
问题 I\'ve seen default used next to function declarations in a class. What does it do? class C { C(const C&) = default; C(C&&) = default; C& operator=(const C&) & = default; C& operator=(C&&) & = default; virtual ~C() { } }; 回答1: It's a new C++11 feature. It means that you want to use the compiler-generated version of that function, so you don't need to specify a body. You can also use = delete to specify that you don't want the compiler to generate that function automatically. With the

Understanding implicit in Scala

老子叫甜甜 提交于 2019-11-26 03:36:50
问题 I was making my way through the Scala playframework tutorial and I came across this snippet of code which had me puzzled: def newTask = Action { implicit request => taskForm.bindFromRequest.fold( errors => BadRequest(views.html.index(Task.all(), errors)), label => { Task.create(label) Redirect(routes.Application.tasks()) } ) } So I decided to investigate and came across this post. I still don\'t get it. What is the difference between this: implicit def double2Int(d : Double) : Int = d.toInt

Alternative to a goto statement in Java

风流意气都作罢 提交于 2019-11-26 03:34:30
问题 What is an alternative function for the goto keyword in Java? Since Java does not have a goto. 回答1: You could use a labeled BREAK statement: search: for (i = 0; i < arrayOfInts.length; i++) { for (j = 0; j < arrayOfInts[i].length; j++) { if (arrayOfInts[i][j] == searchfor) { foundIt = true; break search; } } } However, in properly designed code, you shouldn't need GOTO functionality. 回答2: There isn't any direct equivalent to the goto concept in Java. There are a few constructs that allow you

“register” keyword in C?

狂风中的少年 提交于 2019-11-26 03:22:35
问题 What does the register keyword do in C language? I have read that it is used for optimizing but is not clearly defined in any standard. Is it still relevant and if so, when would you use it? 回答1: It's a hint to the compiler that the variable will be heavily used and that you recommend it be kept in a processor register if possible. Most modern compilers do that automatically, and are better at picking them than us humans. 回答2: I'm surprised that nobody mentioned that you cannot take an

new keyword in method signature

浪子不回头ぞ 提交于 2019-11-26 02:19:22
问题 While performing a refactoring, I ended up creating a method like the example below. The datatype has been changed for simplicity\'s sake. I previous had an assignment statement like this: MyObject myVar = new MyObject(); It was refactored to this by accident: private static new MyObject CreateSomething() { return new MyObject{\"Something New\"}; } This was a result of a cut/paste error on my part, but the new keyword in private static new is valid and compiles. Question : What does the new

When were the &#39;and&#39; and &#39;or&#39; alternative tokens introduced in C++?

感情迁移 提交于 2019-11-26 02:03:03
I've just read this nice piece from Reddit. They mention and and or being "Alternative Tokens" to && and || I was really unaware of these until now. Of course, everybody knows about the di-graphs and tri-graphs , but and and or ? Since when? Is this a recent addition to the standard? I've just checked it with Visual C++ 2008 and it doesn't seem to recognize these as anything other than a syntax error. What's going on? MSVC supports them as keywords only if you use the /Za option to disable extensions; this is true from at least VC7.1 (VS2003). You can get them supported as macros by including

Does the &#39;mutable&#39; keyword have any purpose other than allowing the variable to be modified by a const function?

那年仲夏 提交于 2019-11-26 01:36:43
问题 A while ago I came across some code that marked a member variable of a class with the mutable keyword. As far as I can see it simply allows you to modify a variable in a const method: class Foo { private: mutable bool done_; public: void doSomething() const { ...; done_ = true; } }; Is this the only use of this keyword or is there more to it than meets the eye? I have since used this technique in a class, marking a boost::mutex as mutable allowing const functions to lock it for thread-safety