我正在使用Python v2,我试图找出你是否可以判断一个单词是否在字符串中.
我找到了一些关于识别单词是否在字符串中的信息 - 使用.find,但有没有办法做IF语句.我希望得到以下内容:
if string.find(word):
print 'success'
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
在我的iPhone应用程序中,我有一个我在Interface Builder中创建的UIButton.我可以在我的代码中成功启用和禁用它...
sendButton.enabled = YES;
Run Code Online (Sandbox Code Playgroud)
要么
sendButton.enabled = NO;
Run Code Online (Sandbox Code Playgroud)
但是,按钮的视觉外观总是一样的!它没有褪色或灰色.如果我尝试单击它,则会按预期启用或禁用它.我错过了什么吗?它不应该看起来褪色或灰色?
谢谢
我有一个类Base定义explicit operator bool:
struct Base {
virtual explicit operator bool() const {
return true;
}
};
Run Code Online (Sandbox Code Playgroud)
我有一个子类Derived,定义operator bool:
struct Derived : Base {
operator bool() const override {
return false;
}
};
Run Code Online (Sandbox Code Playgroud)
正如你可以观察到的那样,Derived::operator bool明确没有标记explicit,但是标记了override,所以我期望编译器抱怨.然而,gcc和clang似乎都同意这是有效的.我的期望不合理吗?
而且,如果我使用如下的类,TakesBool(base)不编译(如预期的那样),但是TakesBool(derived):
void TakesBool(bool b) {}
int main() {
//Base base; TakesBool(base); // compilation error (as expected)
Derived derived; TakesBool(derived);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这似乎表明Derived有一个(非explicit)operator …
我设置了一个emacs --daemon以便更快地启动emacs.我特别喜欢emacs的GUI版本,所以我emacsclient -c打开一个新的emacs框架.
问题是我已经改变了我的字体,但是如果我开始的话,这些字体都没有加载emacsclient -c.但是,如果我刚开始应用它们emacs(但这会导致整体.emacs被评估).
那么:如果我开始使用emacs,有没有办法应用我的字体设置emacsclient -c?
我已经了解了通常最好不要在头文件中定义任何内容,因为冗余副本是针对包含头文件的每个其他文件进行的.但是,在静态内联方法的情况下,似乎我必须在现场定义它(至少Visual Studio 2010不允许我这样做).因此,如果我在头文件中编写接口,我就无法定义类定义的静态内联方法或.cpp文件.
那么,我是否应该费心去使用静态内联方法呢?还有一个相关的问题:我是否应该在头文件中定义任何方法或变量(常量怎么样)?
无论如何,奇怪的是,这不是我的C++书籍中非常详细的内容.
编辑:我读过有关静态内联方法的类似问题,但似乎没有一个直接解决这个问题.
#include<cstddef>
template<typename T, std::size_t N>
struct A {
T m_a[N];
A() : m_a{} {}
};
struct S {
explicit S(int i=4) {}
};
int main() {
A<S, 3> an;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码与MSVC(2017)编译良好,但与clang 3.8.0(输出clang++ --version && clang++ -std=c++14 -Wall -pedantic main.cpp)失败:
clang version 3.8.0 (tags/RELEASE_380/final 263969)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
main.cpp:6:15: error: chosen constructor is explicit in copy-initialization
A() : m_a{} {}
^
main.cpp:14:13: note: in instantiation of member function 'A<S, 3>::A' requested here
A<S, 3> an; …Run Code Online (Sandbox Code Playgroud) 基本上,情况如下:
我有一个类模板(使用一个length类型的模板参数int),并想要引入一个静态数组.这个数组应长度的length和包含的元素1到length.
代码如下所示:
template<int length>
class myClass{
static int array[length];
};
Run Code Online (Sandbox Code Playgroud)
然后我想写一行用于初始化数组
// of course, the line below does not work as intended.
template<int length> int myClass<length>::array[length]={1,2, ..., length};
Run Code Online (Sandbox Code Playgroud)
(如何)可以实现这一目标?
我有一个包含多列的网格,我使用第一列作为行标签.我查看了使网格可编辑的示例,但这似乎使整个网格可编辑.是否仅指定某个列?