我有这段代码:
public class ThreadInteraction {
public static void main(String[] argv) {
System.out.println("Create and start a thread t1, then going to sleep...");
Thread1 t1 = new Thread1();
t1.start();
try{
Thread.sleep(1000);
}
catch(InterruptedException e) {
System.out.println(e.toString());
}
//let's interrupt t1
System.out.println("----------- Interrupt t1");
t1.interrupt();
for(int i =0; i<100; i++)
System.out.println("Main is back");
}
}
class Thread1 extends Thread {
public void run() {
for(int i =0; i<10000; i++)
System.out.println(i + "thread1");
}
}
Run Code Online (Sandbox Code Playgroud)
它似乎t1.interrupt()不起作用,因为在我的输出中出现所有10000 t1打印.难道我做错了什么?
我正在做一个项目,在该项目中我必须创建一个可以为 C 代码生成 MIPS 汇编代码的翻译器。我使用的编程语言是 C++,我已经完成了三个地址代码的生成,并且对如何进一步进行感到非常困惑。
在C++程序中,我正在尝试处理用户输入,其中包含散布有运算符的整数操作数(+ - /*).我很高兴要求用户在每个操作员之前和之后放置空格.我的方法是假设任何不是int的东西都是运算符.因此,只要流上出现非eof错误,我就会调用cin.clear()并将下一个值读入字符串.
#include <iostream>
#include <string>
//in some other .cpp i have these functions defined
void process_operand(int);
void process_operator(string);
using namespace std;
int main()
{
int oprnd;
string oprtr;
for (;; )
{
while ( cin >> oprnd)
process_operand(oprnd);
if (cin.eof())
break;
cin.clear();
cin >> oprtr;
process_operator(oprtr);
}
}
Run Code Online (Sandbox Code Playgroud)
这适用于/和*运算符,但不适用于+ - 运算符.原因是 operator>>在报告错误之前吃掉了+或 - 并且没有将它放回到流上.所以我得到一个无效的令牌读入oprtr.
Ex: 5 1 * 2 4 6 * / works fine
5 1 + 2
^ ---> 2 becomes the oprnd here.
Run Code Online (Sandbox Code Playgroud)
什么是一个很好的C++方式来处理这个问题?
我正在研究一个简单的自上而下的射击游戏,并希望将我的船只移到一个单独的ShipManager类,在那里我可以从一个位置管理所有这些.但是,在启动时,我的playerShip上出现了一个链接器错误:
错误LNK2001:未解析的外部符号"public:static class Ship*ShipManager :: playerShip"
ShipManager.h如下所示:
class Ship;
class ShipManager
{
public:
static Ship* playerShip;
};
Run Code Online (Sandbox Code Playgroud)
我在ShipManager .cpp中什么都没有.我错过了什么?我使用此代码的唯一其他地方是在我的游戏类中,我实际上正在调用ShipManager :: playerShip,我没有在那里得到任何错误.
我在我的game.cpp中包含"ShipManager.h",所以应该找到它吗?我有一种感觉,我在这堂课中忘记了一些简单的事情.
我正在尝试将一个小的实用程序应用程序更新为更现代的C++方式,但是我在使用std :: shared_ptr的一些Qt对象时遇到了问题,特别是那些接收其他QWidget作为构造函数参数的那些.
例如:
private:
std::shared_ptr<QWidget> centralwidget;
std::shared_ptr<QVBoxLayout> verticalLayout;
public:
void setupUi(QMainWindow *MainWindow) // this pointer is a .get() from a shared_ptr
{
centralwidget = std::make_shared<QWidget>(new QWidget(MainWindow)); // compiles fine
verticalLayout = std::make_shared<QVBoxLayout>(new QVBoxLayout(centralwidget.get())); // does not compile
}
Run Code Online (Sandbox Code Playgroud)
编译错误是:
错误1错误C2664:'QVBoxLayout :: QVBoxLayout(QWidget*)':无法将参数1从'QVBoxLayout*'转换为'QWidget*'e:\ microsoft visual studio 11.0\vc\include\memory 855
我似乎无法理解这个错误,我没有转换任何东西,我只是想创建一个QVBoxLayout对象并传递一个QWidget作为其父(就像我会用原始指针).
据我所知,分发iOS应用程序的方法有两种:
1)应用程序商店:应用程序将向公众开放
2)Ad-Hoc:app将被共享到一组设备(最多100个)
我为公司构建了一个应用程序,他们希望只有100多台设备才能让员工看到该应用程序.因此,Ad-Hoc方法将无效.
我想知道是否有办法在App Store上发布应用程序,但将其隐藏起来.即,如果有人搜索它,应用程序将只显示?
我有什么选择?
我想在一个独立的dll中包含一组样式,可以从许多不同的WOF类中引用它们来定义常见样式.
我已经创建了独立的dll并尝试引用它但是遇到了问题.
这是独立dll的代码:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Style x:Key="myStyle" TargetType="Button">
<Setter Property="Background" Value="Orange" />
<Setter Property="FontStyle" Value="Italic" />
<Setter Property="Padding" Value="8,4" />
<Setter Property="Margin" Value="4" />
</Style>
<!-- store here your styles -->
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
这是我试图引用它的地方:
<src:GX3ClientPlugin.Resources>
<ResourceDictionary Source="pack://application:,,,/GX3StyleResources.dll;component/GX3StyleResources.xaml" />
</src:GX3ClientPlugin.Resources>
Run Code Online (Sandbox Code Playgroud)
运行时,我得到以下异常:
无法加载文件或程序集"GX3StyleResources.dll,Culture = neutral"或其依赖项之一.该系统找不到指定的文件.
有任何想法吗?
当我尝试使用AVR studio 4调试一小段代码时出现此错误:
Build failed... No build tools defined.
Run Code Online (Sandbox Code Playgroud)
有人可以给我一些建议吗?
我提到了两个可靠的信息来源,两者似乎对同一事物有不同的定义:
http://www.cplusplus.com/reference/clibr%E2%80%A6
http://www.ocf.berkeley.edu/~pad/tigcc/doc/html/stdio_fputchar.html
第一个来源说的putchar()是一个函数,getchar()但是在第二个链接中它表示putchar()是一个宏.我的书说getchar()是一个宏.哪个是对的?