Java程序员和API似乎更喜欢显式的set/get方法.
但是我得到了C++社区对这种做法不满的印象.如果是这样,是否有一个特殊的原因(除了更多的代码行)为什么会这样?
另一方面,为什么Java社区选择使用方法而不是直接访问?
谢谢
我需要有关如何编写一个C程序的想法,该程序保留指定数量的MB RAM直到一个键[ex.在Linux 2.6 32位系统上按下任意键.
*
/.eat_ram.out 200
# If free -m is execute at this time, it should report 200 MB more in the used section, than before running the program.
[Any key is pressed]
# Now all the reserved RAM should be released and the program exits.
*
Run Code Online (Sandbox Code Playgroud)
它是程序的核心功能[保留RAM]我不知道怎么做,从命令行获取参数,打印[按任意键]等等对我来说不是问题.
关于如何做到这一点的任何想法?
我最近开始关注boost phoenix,作为lambda的替代品.凤凰是lambda的完全替代品,还是凤凰城没有提供一些lambda功能?是凤凰成熟吗?有什么问题我应该知道吗?
我的主要兴趣是操作员组成,控制语句和演员表不那么重要
谢谢
有没有办法记录模板参数,如下所示:
template<
int N, ///< description
typename T ///< description
>
Run Code Online (Sandbox Code Playgroud)
而不是列出每个参数tparam?
请注意,函数参数可以在当前的doxygen中记录如下:
void function(int a /**< description */);
Run Code Online (Sandbox Code Playgroud)
如果没有,实施它会有多难?如果你熟悉doxygen内部,你能指出我实施它的方向.
谢谢
我有以下情况:假设我有一堆类型(仿函数),我想在编译期间注册/编译,最好是像boost :: mpl :: vector.你知道这么做的诀窍吗?
我的愿望是拥有实现仿函数类型和注册文件的hpp文件,其中宏将类型引入编译.
例如
// registered.hpp
REGISTER("functor1.hpp") // implementation
REGISTER("functor2.hpp")
...
boost::mpl::vector<...> types; // full registration vector
Run Code Online (Sandbox Code Playgroud)
希望这是有道理的.谢谢
可以使用初始化列表创建结构/类的对象(没有构造函数).为什么在构造函数的 struct/class上不允许这样做?
struct r { int a; };
struct s { int a; s() : a(0) {} };
r = { 1 }; // works
s = { 1 }; // does not work
Run Code Online (Sandbox Code Playgroud) 我偶然发现了Adobe源库ASL.在MIT许可下,它是一组类似于boost的模板和功能.我发现库中的一些实用程序非常有用,现在我考虑使用它.
然而,图书馆似乎很简单.
谢谢
我无法弄清楚为什么这个段给出了未解决的重载函数错误(gcc版本4.3.4(Debian 4.3.4-6)):
#include <algorithm>
#include <boost/function.hpp>
// this does not work
int main1()
{
typedef boost::function<const int&(const int&, const int&)> max;
max m(&std::max<int>);
}
// this does not work
int main2() {
typedef boost::function2<const int&, const int&, const int&> max;
max m(static_cast<max>(&std::max<int>));
}
Run Code Online (Sandbox Code Playgroud)
你能帮助我吗,谢谢
test.cpp: In function âint main()â:
test.cpp:7: error: no matching function for call to âboost::function2<const int&, const int&, const int&>::function2(<unresolved overloaded function type>)â
/usr/include/boost/function/function_template.hpp:747: note: candidates are: boost::function2<R, T1, T2>::function2(const boost::function2<R, T1, T2>&) [with R = const …Run Code Online (Sandbox Code Playgroud) 我稍微改变了标题因为我认为这是更合适的问题.
你会重构它(似乎合法使用goto)?如果,您将如何重构以下代码以删除转到语句?
if (data.device) {
try {
...
}
catch(const std::exception&) { goto done; }
... // more things which should not be caught
done: ;
}
Run Code Online (Sandbox Code Playgroud)
完整的声明
#ifdef HAVE_GPU
// attempt to use GPU device
if (data.device) {
try {
Integral::Gpu eri(S, R, Q, block.shell());
eri(basis.centers(), quartets, data.device);
}
// if GPU fails, propagate to cpu
catch(std::exception) { goto done; }
data.device += size;
host_index.extend(block_index);
block_index.data.clear();
done: ;
}
#endif
Run Code Online (Sandbox Code Playgroud)
谢谢
在看过大多数人的偏好之后,我决定带着旗帜,但是约克先生发表评论.
谢谢大家