为什么这个程序打印"未添加"而我认为它应该打印"添加"?
using System;
using System.Collections.Generic;
class Element
{
public int id;
public Element(int id)
{
this.id = id;
}
public static implicit operator Element(int d)
{
Element ret = new Element(d);
return ret;
}
public static bool operator ==(Element e1, Element e2)
{
return (e1.id == e2.id);
}
public static bool operator !=(Element e1, Element e2)
{
return !(e1.id == e2.id);
}
}
class MainClass
{
public static void Main(string[] args)
{
List<Element> element = new List<Element>();
element.Add(2);
if(element.Contains(2))
Console.WriteLine("added"); …
Run Code Online (Sandbox Code Playgroud) 让
int a = 0;
Run Code Online (Sandbox Code Playgroud)
那么是标准C++中(int)a
的右值?
不同的编译器显示此代码的不同结果:
#include <iostream>
using namespace std;
void f(int& x)
{
cout << "l value" << endl;
}
void f(int&& x)
{
cout << "r value" << endl;
}
int main()
{
int a = 0;
f((int)a);
}
Run Code Online (Sandbox Code Playgroud)
编译器有不同的结果:
从技术上讲,在C#中声明,实例化,初始化和分配对象的术语的含义和区别是什么?
我想我知道分配的意思,但我没有正式的定义.
在msdn中,有人说"创建对象的行为称为实例化".但创造的意义对我来说似乎含糊不清.你可以写
int a;
Run Code Online (Sandbox Code Playgroud)
在a
随后产生的?
为什么
cout<< "??????";
Run Code Online (Sandbox Code Playgroud)
效果很好
wcout<< L"??????";
Run Code Online (Sandbox Code Playgroud)
才不是?(在Qt Creator for linux中)
我尝试编写一个程序,它挂钩键盘消息,在Ubuntu(KDE)中按下时发出每个键的名称; 不干扰程序中键盘的正常操作(只是宣布键名).
这是我的计划:
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;
void SendPressKeyEvent(Display *display, XKeyEvent xkey)
{
Window current_focus_window;
int current_focus_revert;
XGetInputFocus(display, ¤t_focus_window, ¤t_focus_revert);
xkey.type = KeyPress;
xkey.display = display;
xkey.window = current_focus_window;
xkey.root = DefaultRootWindow(display);
xkey.subwindow = None;
xkey.time = 1000 * time(0);
xkey.x = 0;
xkey.y = 0;
xkey.x_root = 0;
xkey.y_root = 0;
xkey.same_screen = True;
XSendEvent(display, InputFocus, True, KeyPressMask, (XEvent *)(&xkey));
}
void SendReleaseKeyEvent(Display *display, XKeyEvent xkey)
{
Window current_focus_window;
int …
Run Code Online (Sandbox Code Playgroud) 我在 Visual Studio 2017 C++17 中收到以下程序的错误:
#include <iostream>
int main()
{
using namespace std;
align_val_t alignment = (align_val_t)1024;
int* p = new(alignment) int(3);
cout << (unsigned long long)(p) % 1024;
delete p;
}
Run Code Online (Sandbox Code Playgroud)
错误 C2956 大小的释放函数“operator delete(void*, size_t)”将被选为放置释放函数
该程序在 gcc-8 中编译没有错误。VS中的程序如何解决?
使用C#-8.0的.Net Core Console应用程序中以下界面没有错误
interface I
{
public abstract void f();
public virtual void g() => Console.WriteLine("g");
public sealed void h() => Console.WriteLine("h");
}
Run Code Online (Sandbox Code Playgroud)
abstract
防止在接口中添加定义。virtual
并且sealed
需要在接口中进行定义。sealed
阻止派生类中的实现h
。
abstract
在接口中使用、virtual
和 sealed
时,在当前实现的 C# - 8 版本中还有其他含义或应用吗?它们应该如何以及何时在界面中使用?
这个程序有两个错误:
using System;
T? f<T>(T? t)
{
t = null; // Error CS0403 Cannot convert null to type parameter 'T' because it could be a non-nullable value type
return default(T?);
}
if(f(10) is null) // Error CS0037 Cannot convert null to 'int' because it is a non-nullable value type
Console.WriteLine("null");
Run Code Online (Sandbox Code Playgroud)
T?
必须是可空类型。不过好像和上面的程序T?
是一样的T
。
被?
忽略T?
?
using System;
T? f<T>(T? t) where T : struct
{ …
Run Code Online (Sandbox Code Playgroud) 尝试编译代码时,IDE 中显示的致命错误和非致命错误之间的主要区别是什么?
在这两种情况下,编译器都会显示一条错误消息,并且不会编译程序。致命错误是编译器或链接器中未定义的编译器错误吗?
我用这个代码:
MyDialog *md = new MyDialog();
md -> show();
Run Code Online (Sandbox Code Playgroud)
在Qt中打开一个对话框窗口.md
关闭对话框窗口时会自动删除,还是delete md
在窗口完成后需要运行?