:- dynamic plop/2
add(Var):-
retract(plop(Var,X))->
(X = X+1, assert(plop(Var,X)));
(assert(plop(Var,1))).
Run Code Online (Sandbox Code Playgroud)
所以,如果我调用add(y).它会创建plop(y,1)但是当我调用add(y)时.再次为什么不添加一个所以它将是plop(y,2)
我试图在我的链表空为止时抛出一个EmptyListException,但是如果我取消注释throw EmptyListException(),程序将继续终止.这是我的EmptyListException标头
#ifndef EMPTYLISTEXCEPTION_H
#define EMPTYLISTEXCEPTION_H
#include <stdexcept>
using std::out_of_range;
class EmptyListException : public out_of_range
{
public:
EmptyListException(): out_of_range("Empty List!\n") {}
};
#endif // EMPTYLISTEXCEPTION_H
Run Code Online (Sandbox Code Playgroud)
- 在Clist.h中抛出命令
template <typename E>
E Clist<E>::Remove() throw()
{
if(isEmpty())
{
cout << "Empty List, no removal";
//throw EmptyListException();
return '.';
}
... code
}
Run Code Online (Sandbox Code Playgroud)
- 赶上主要
try{
cout << list->Remove() << endl;
} catch(EmptyListException &emptyList)
{
cout << "Caught :";
cout << emptyList.what() << endl;
}
Run Code Online (Sandbox Code Playgroud)
错误'此应用程序已请求运行时以不寻常的方式终止它.有关更多信息,请联系应用程序的支持团队.
我试图填补考试,这些是一些最艰难的例子
Movie(title, year, director, budget, earnings)
Actor(stagename, realname, birthyear)
ActedIn(stagename, title, year, pay)
CanWorkWith(stagename, director)
Run Code Online (Sandbox Code Playgroud)
对于2006年在电影中扮演角色的每个演员,在他们演过的所有电影中找到他们的舞台名称和总薪酬(即包括那些不在2006年的电影).
对于每个可以与至少5位演员合作的导演,可以找到导演每年制作电影时制作的电影总数.