[英]Is there an equivalent in Structured Text for C++ templates?
我是结构化文本编程的新手,目前正在研究 TwinCat3。
我想在我的代码中指定数组大小,而不用额外的常量污染全局命名空间。 我认为它会很有用,尤其是在创建库时。
我找不到这个问题的解决方案。 如果没有,你能告诉我解决这个问题的最佳实践吗? 我看到的唯一解决方案是:
你可以尝试这样的事情。
class <someclass>{
public:
static const int ARR_SIZE;
}
const int X::ARR_SIZE = <somevalue>;
由于变量是 class scope,因此您不会污染全局命名空间。 或者,您可以创建自己的命名空间并在其中定义 static const 变量,例如
namespace <somename>{
static const int ARR_SIZE = <somevalue>;
// other definitions.
}
在这种情况下, const 变量在命名空间内只读且可访问,并且可以通过命名空间外的::ARR_SIZE 访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.