谁能解释一下是NSRunLoop
什么?所以我知道这NSRunLoop
是一件与之相关的事情NSThread
吗?所以假设我创建一个类似的线程
NSThread* th=[[NSThread alloc] initWithTarget:self selector:@selector(someMethod) object:nil];
[th start];
-(void) someMethod
{
NSLog(@"operation");
}
Run Code Online (Sandbox Code Playgroud)
在这个线程完成他的工作之后?为什么使用RunLoops
或在哪里使用?从Apple docs我已经阅读了一些东西,但对我来说并不清楚,所以请尽可能简单地解释
我试过制作(我的第一个)C#程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这很顺利,但如果我尝试使用System.Windows.Forms:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello");
System.MessageBox("hello");
Console.ReadLine();
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
Error 1 The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?) C:\Users\Ramy\Documents\Visual Studio 2010\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 5 14 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试执行以下操作:
template <class T>
std::ifstream& operator>> (std::ifstream& fin, List<T> l)
{
T temp;
l.resize(0);
fin >> ignore(1,'\t');
for(ListIterator<T> i=l.begin();i!=l.end();i++)
{
fin >> ignore(1,'\t') >> temp;
l.push_back(temp);
}
return fin;
}
Run Code Online (Sandbox Code Playgroud)
我必须从文件中读取所有内容.每个字段都按'\t'
字符分隔,因此我必须忽略'\t'
字符.
错误日志如下:
/home/ramy/Documents/C++/Prova/Util.h||In function ‘std::ifstream& Util::operator>> (std::ifstream&, Util::List<T>)’:|
/home/ramy/Documents/C++/Prova/Util.h|431|error: there are no arguments to ‘ignore’ that depend on a template parameter, so a declaration of ‘ignore’ must be available|
/home/ramy/Documents/C++/Prova/Util.h|431|note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared …
Run Code Online (Sandbox Code Playgroud) 我已经安装了具有Qt的C++ SDK,但是当我尝试编译链接QApplication的代码时,它给了我错误:
Error QApplication: no such file or directory
Run Code Online (Sandbox Code Playgroud)
如何链接这些库?我搜索了目录,有一个名为QApplication.h的文件; 所以我尝试将它与-I(链接目录)链接,但它仍然给我这个错误.
是否可以在收到通知时增加徽章值.或者我应该将计数作为有效载荷发送?
如果我每次都将徽章值发送为"1",如果应用程序未打开,我怎么能增加应用程序图标中的徽章值.
我使用过这段代码但不起作用.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[UIApplication sharedApplication].applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber + 1;
}
Run Code Online (Sandbox Code Playgroud) 十进制类使用96位作为积分部分,1位作为符号,5位作为比例因子.26位未使用,最大值为7.9e28,因为最大指数为28.
使用其他26位,精度会更高.这个实现选择的原因是什么?
假设我有一个A类,B,C,D是从A派生的.
如果我想知道引用的对象的类型是什么,我可以声明:
// pseudo-code
if(obj instanceof B)
< is B>
else if(obj instanceof C)
< is C>
else
<is D>
Run Code Online (Sandbox Code Playgroud)
这是因为我确信从A派生的类只有B,C和D.
但是,如果我只想检查两个引用是否指向同一种对象呢?
所以类似于:
if(obj1 instanceof obj2)
<do something>
Run Code Online (Sandbox Code Playgroud)
但当然语法是错误的.如果没有一千个if-else怎么检查呢?
我试图计算一个人在数据库中的年龄.
我们假设有这个简单的表格:
student(id, birth_date);
Run Code Online (Sandbox Code Playgroud)
其中id是主键(实际上表格更复杂但我简化了它).
我想知道一个人多大年纪:
select id, datediff(curdate(),birth_date)
from student
Run Code Online (Sandbox Code Playgroud)
但是它会在几天内返回结果,而不是几年.我可以将它除以365:
select id, datediff(curdate(),birth_date) / 365
from student
Run Code Online (Sandbox Code Playgroud)
但它返回一个浮点值,我想要一个整数.
所以我可以计算年数:
select id, year(curdate())-year(birth_date)
from student
Run Code Online (Sandbox Code Playgroud)
但是有一个问题:比如现在是5月,如果一个人在1970年6月出生的战争他还有31年而不是32岁,但表达式返回32.
我不能摆脱这个问题,有人可以帮我吗?
如果我有一个va_list,我知道如何提取它的所有元素:
void printInts(int n,...)
{
va_list va;
va_start(va, n);
for(unsigned int i=0; i<n; i++)
{
int arg=va_arg(va, int);
printf("%d",arg);
}
va_end(va);
}
Run Code Online (Sandbox Code Playgroud)
因此,当我调用printInts(3,1,2,3)时,va_list将填充所有参数.
但是如何在不使用va_start的情况下手动填充va_list?我的意思是我想要这样的东西:
va_list va;
push_arg(va, int, 5); // And so on until I fill all parameters
...
Run Code Online (Sandbox Code Playgroud)
我需要这个,因为有一个函数接受va_list作为参数,我不知道如何填充其所有参数的va_list.
如果我有这样的抽象类:
public abstract class Item
{
private Integer value;
public Item()
{
value=new Integer(0);
}
public Item(Integer value)
{
this.value=new Integer();
}
}
Run Code Online (Sandbox Code Playgroud)
有些类派生自Item,如下所示:
public class Pencil extends Item
{
public Pencil()
{
super();
}
public Pencil(Integer value)
{
super(value);
}
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么我不能使用泛型调用构造函数:
public class Box <T extends Item>
{
T item;
public Box()
{
item=new T(); // here I get the error
}
}
Run Code Online (Sandbox Code Playgroud)
我知道有可能有一个没有构造函数的类型,但这种情况是不可能的,因为Pencil有没有参数的构造函数,而Item是抽象的.但我从eclipse得到这个错误:
不能实现类型T
我不明白为什么,以及如何避免这种情况?