我可以在set迭代器中获取类的方法吗?
#include <iostream>
#include <string>
#include <set>
class student{
public:
student(std::string n){
name=n;
}
void print(){
std::cout << name << std::endl;
}
bool operator < (const student & s1){ return true;}
bool operator = (const student & s1){ return true;}
private:
std::string name;
};
int main(){
std::set<student> studs;
studs.insert(student("name01"));
studs.insert(student("name02"));
std::set<student>::iterator it;
for(it = studs.begin(); it != studs.end(); it++)
(*it).print() ;
}
Run Code Online (Sandbox Code Playgroud)
我收到这个错误
students.cpp: In function ‘int main()’:
students.cpp:22: error: passing ‘const student’ as ‘this’ argument of ‘void student::print()’ discards …Run Code Online (Sandbox Code Playgroud) 我们有三个班级;
Line
PoliLine
SuperPoliLine
Run Code Online (Sandbox Code Playgroud)
因为所有三个类都Distance被定义了.
但只有Linea Distance可以设置.
是否有可能构建一个公共抽象(MustInherit)类Segment,具有Distanceas(abstract +?ReadOnly)成员?
关于VB.NET的问题,但C#答案也受到了欢迎.
商业背景
想象一下公共汽车.它有很多Stations,MainStations和2 TerminalStations.因此Line位于2个站之间,PoliLine介于2 MainStation秒之间,SuperPoliLine位于2个TerminalStations之间.所有"线"都是"分段",但只有两个站之间的距离A-> B - 可以定义线.
我一直在关注Railscast,为我的应用添加搜索,排序和分页功能.我在模型中修改了我的搜索逻辑以搜索列(描述和标题).这似乎有效.我也改变它来搜索非区分大小写.这似乎在我的本地应用程序中完美,但是当我将它推送到heroku时,我只能用小写字母搜索.即使案例与结果匹配,使用任何大写字母搜索都不会产生任何结果.
这是我模型中的代码:
def self.search(search)
if search
where('LOWER (description) LIKE ? OR LOWER (title) LIKE ?', "%#{search}%" , "%#{search}%")
else
scoped
end
end
Run Code Online (Sandbox Code Playgroud) 在Java中获取字符串的最后一个字的最简单方法是什么?你可以假设没有标点符号(只是字母字符和空格).
我无法理解 C++ 类中私有成员和受保护成员之间的区别。简单来说,有什么区别?
我正在为一个网站制作一个注册表格,因为我确定每个人都会在Secret Answer的输入中输入一些胡言乱语(我自己这样做),我想以编程方式测试该值,看看它是否更有可能是一个很好的答案.
我已经看了一个在PHP中生成马尔可夫链的函数(见下图),但我不知道如何针对那些链'Array测试字符串来实际检测给定答案的%准确度.
这里有人做过类似的事吗?你是如何解决它或让你放弃的?
谢谢
function generateCaptchaTextMarkov($length) {
$transitionMatrix = array(
0.0001, 0.0218, 0.0528, 0.1184, 0.1189, 0.1277, 0.1450, 0.1458, 0.1914, 0.1915, 0.2028, 0.2792, 0.3131, 0.5293, 0.5304, 0.5448, 0.5448, 0.6397, 0.7581, 0.9047, 0.9185, 0.9502, 0.9600, 0.9601, 0.9982, 1.0000,
0.0893, 0.0950, 0.0950, 0.0950, 0.4471, 0.4471, 0.4471, 0.4471, 0.4784, 0.4821, 0.4821, 0.6075, 0.6078, 0.6078, 0.7300, 0.7300, 0.7300, 0.7979, 0.8220, 0.8296, 0.9342, 0.9348, 0.9351, 0.9351, 1.0000, 1.0000,
0.1313, 0.1317, 0.1433, 0.1433, 0.3264, 0.3264, 0.3264, 0.4887, 0.5454, 0.5454, 0.5946, 0.6255, 0.6255, 0.6255, 0.8022, 0.8022, 0.8035, …Run Code Online (Sandbox Code Playgroud) 我在Word 2007中设置行间距时遇到问题.Word 2007默认为双倍间距或行之间有额外的空格.以前,我总是使用类似的东西成功(在C#中):
//No spacing when using Word version > 2003
//Word 2003 = "11.0"
//Word 2007 = "12.0"
Word.Application appVersion = new Word.Application();
string sVersion = appVersion.Version.ToString();
if (sVersion != "11.0")
{
object noSpacingStyle = "No Spacing";
oWord.ActiveWindow.Selection.set_Style(ref noSpacingStyle);
}
Run Code Online (Sandbox Code Playgroud)
但是,当尝试在一些地区/文化环境中应用它时,例如意大利语和德语,这种情况就会破裂.我相信这是因为"No Spacing"需要使用目标语言,而不是硬编码为英语.所以,我试图想出一种以更便携的方式应用这种相同变化的方法.
我已经尝试过各种枚举,例如"WdBuiltinStyle",但似乎找不到与"无间距"完成相同的事情.
这里有谁知道如何做到这一点?
大家好.我想排序并返回按日期排序的元组的一部分.
我只想将第一个到第四个记录(元组[:3])排序并打印出来.
tuple = [('Dec 1, 2010', '7.41', '7.60', '7.37'),
('Dec 4, 2010', '7.41', '7.60', '7.37'),
('Dec 2, 2010', '7.41', '7.60', '7.37'),
('Dec 20, 2010', '7.41', '7.60', '7.37'),
('Dec 16, 2010', '7.41', '7.60', '7.37'),
('Jan 2, 2011', '7.41', '7.60', '7.37')]
Run Code Online (Sandbox Code Playgroud)
我试过了:
import operator
sorted(tuple[:3], key=operator.itemgetter('date'), reverse=True)
Run Code Online (Sandbox Code Playgroud)
但是,它返回错误"TypeError:元组索引必须是整数,而不是str.
我认为or是c ++中的关键字.
可能是我最近做了太多的python代码,但我发现or它比可读性更强||,xor更易读^.
使用符号运算符替代词这个词是个好主意吗?
为什么我看不到他们使用更多?
我有一个具有文件输入控件的表单:
<input type="file" onclick="this.blur()" name="descFile" />
Run Code Online (Sandbox Code Playgroud)
因此,当用户选择文件时,路径显示在文本输入框中(默认浏览器行为),但是,企业希望我在下面用粗体字母添加一条消息,表明他们已经选择了要上传的文件,然后回发.
有没有办法使用Javascript以某种方式从文件输入捕获"选择"事件并在文件输入下方以粗体字母显示?