我有一个将转换为的类std::string。除了接收函数std::basic_string<T>(在上模板化T)外,它适用于所有事物。
#include <string>
struct A{
operator std::string(){return std::string();}
};
void F(const std::basic_string<char> &){}
template<typename T> void G(const std::basic_string<T> &) {}
int main(){
A a;
F(a); // Works!
G(a); // Error!
return 0; // because otherwise I'll get a lot of comments :)
}
Run Code Online (Sandbox Code Playgroud)
我收到的错误是
error: no matching function for call to 'G(A&)'
note: candidate is:
note: template<class T> void G(const std::basic_string<_CharT>&)
Run Code Online (Sandbox Code Playgroud)
现在,我知道可以G在struct中定义为好友A并且可以使用,但是我的问题是很多已经存在并接收到的stl函数std::basic_string<T>(例如,operator<<打印函数,比较运算符或许多其他函数) 。
我真的很想能够A像它一样使用 …
我有很多名字的变量
PRE_adam
POST_adam
PRE_betty
POST_betty
PRE_clara
POST_clara
...
Run Code Online (Sandbox Code Playgroud)
对于很多人的名字.
我想计算之间的差异PRE_X和POST_X对名单X的S -是这样的:
COMPUTE DIFF_adam = POST_adam - PRE_adam
COMPUTE DIFF_betty = POST_betty - PRE_betty
COMPUTE DIFF_clara = POST_clara - PRE_clara
Run Code Online (Sandbox Code Playgroud)
有没有办法在循环中执行此操作?像这样的东西:
DO REPEAT x= adam betty clara
COMPUTE !concat('DIFF_',x) = !concat('POST_',x) - !concat('PRE_',x)
END REPEAT
Run Code Online (Sandbox Code Playgroud)
我正在研究一个Arduino项目.我正在尝试将a传递byte pointer给a function,并让它function计算指针引用的数据的大小.但是,当我让指针引用一个字节时,sizeof()返回2.我编写了以下代码片段来尝试调试:
byte b;
byte *byteptr;
byteptr = &b;
print("sizeof(b): ");
println(sizeof(b));
print("sizeof(*byteptr) pointing to byte: ");
println(sizeof(*byteptr));
print("sizeof(byteptr) pointing to byte: ");
println(sizeof(byteptr));
Run Code Online (Sandbox Code Playgroud)
打印结果是:
sizeof(b): 1
sizeof(*byteptr) pointing to byte: 1
sizeof(byteptr) pointing to byte: 2
Run Code Online (Sandbox Code Playgroud)
所以一个字节的大小是1,但是通过指针它是2?