有没有办法在初始化矩阵时以相同,快速的方式初始化矢量矢量?
typedef int type;
type matrix[2][2]=
{
{1,0},{0,1}
};
vector<vector<type> > vectorMatrix; //???
Run Code Online (Sandbox Code Playgroud) 所以,我正在尝试编写一个匹配所有数字的正则表达式.这是正则表达式:
/\b[\d \.]+\b/g
Run Code Online (Sandbox Code Playgroud)
我尝试在字符串上使用它:
100 two 100
Run Code Online (Sandbox Code Playgroud)
一切正常; 它匹配两个数字.
但是我想在表单中重写正则表达式:
new RegExp(pattern,modifiers)
Run Code Online (Sandbox Code Playgroud)
因为我觉得它看起来更清晰.所以我这样写:
new RegExp('\b[\d \.]+\b','g')
Run Code Online (Sandbox Code Playgroud)
但现在它与前一个测试字符串不匹配.我已经尝试了一切,但我无法让它发挥作用.我究竟做错了什么?
所以,我正在尝试在Elisp中创建一个通用的Web搜索功能:
(defun look-up-base (url-formatter)
(let (search url)
(setq search(thing-at-point 'symbol))
(setq url (url-formatter search))
(browse-url url))
)
Run Code Online (Sandbox Code Playgroud)
此功能只会抓取光标下的单词,使用url-formatter格式化网页搜索,然后在Web浏览器中打开搜索字符串以执行搜索.
接下来,我尝试使用前一个函数作为基础来实现一个函数,它将谷歌光标下的单词.
(defun google ()
(interactive)
(look-up-base (lambda (search) (concat "http://www.google.com/search?q=" search))))
Run Code Online (Sandbox Code Playgroud)
如果我尝试评估它,Emacs不会抱怨,但当我尝试使用它时,Emacs给了我这个错误消息:
setq: Symbol's function definition is void: url-formatter
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会这样.我看不出这个功能有什么问题,我做错了什么?
我想使用向量来保存大小为5x5的只读整数矩阵
vector<const int[5][5]> startingPieces;
Run Code Online (Sandbox Code Playgroud)
但是这个声明引起了一系列我以前从未见过的奇怪错误.
error C2535: 'const int (*std::allocator<_Ty>::address(const int (&)[5][5]) const)[5][5]' : member function already defined or declared
1> with
1> [
1> _Ty=const int [5][5]
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\xmemory(109) : see declaration of 'std::allocator<_Ty>::address'
1> with
1> [
1> _Ty=const int [5][5]
1> ]
1> c:\program files\microsoft visual studio 9.0\vc\include\vector(429) : see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1> with
1> [
1> _Ty=const int [5][5]
1> ]
1> c:\program files\microsoft …Run Code Online (Sandbox Code Playgroud) 算法remove和remove_if与成员函数erase之间的区别是什么? 它们是否都会导致调用已删除的对象析构函数?
试着在C#中编写我的第一个泛型类:
public class HighScoreList<ScoreType>
where ScoreType : System.IComparable<ScoreType>
{
...
public HighScoreList(List<ScoreType> highScoreList)
{
....
}
...
}
Run Code Online (Sandbox Code Playgroud)
我遇到了为它编写单元测试的问题.它不能由于某种原因匹配构造函数的参数列表并给出错误:
错误7"TDGLX.FileManagement.HighScoreList.HighScoreList(System.Collections.Generic.List)"的最佳重载方法匹配包含一些无效参数C:\ Users\eric\Documents\Visual Studio 2010\Projects\TDGLX\UnitTests\FileManagmentTest\HighScoreListTest.cs 183 54单元测试
在这个和其他几个测试:
HighScoreList<GenericScore> highScoreList =
new HighScoreList<GenericScore>(new List<GenericScore>()
{
new GenericScore("Person1",400),
new GenericScore("Person2",200),
new GenericScore("Person3",100)
});
HighScoreList<GenericScore> target =
new HighScoreList<GenericScore>(highScoreList);
Run Code Online (Sandbox Code Playgroud)
这是我在测试中用作模板参数列表参数的类.
[Serializable()]
public class GenericScore : System.IComparable<GenericScore>
{
public GenericScore(string name,int score)
{
Name = name;
Score = score;
}
public string Name { get; set; }
public int Score { get; set; }
public …Run Code Online (Sandbox Code Playgroud) 查看二叉树的源代码,我找到以下函数:
//definition of BTR,in case you'd want to know
template< class Type>
struct BTR
{
// The item saved to that specifiec position into the tree
Type value;
// Points to the left leaf
BTR<Type>* left;
// Points to the right leaf
BTR<Type>* right;
};
//why typename?
template< class Type>
BTR<Type>* CreateEx(typename const std::vector<Type>::iterator start,typename const std::vector<Type>::iterator end)
{
//definition
}
Run Code Online (Sandbox Code Playgroud)
现在,让我对这个功能感到困惑的是它的参数.为什么需要关键字typename?因为如果我删除这两个类型名称,我的编译器开始抱怨并说我应该在标识符'start'之前加上')'.如果我更改了参数以便函数使用两个向量而不是两个迭代器并删除了类型名称,我的编译器就会停止抱怨(当然,该函数不再起作用).
// perfectly acceptable!
template< class Type>
BTR<Type>* CreateEx( const std::vector<Type> start, const std::vector<Type> end)
Run Code Online (Sandbox Code Playgroud)
所以我似乎需要关键字,因为该函数需要两个迭代器.但是为什么在这样的情况下这个关键字是必要的呢?