小编Max*_*Max的帖子

使用Wix在注册表值中引用目录安装路径

我想在Windows注册表中保存我的应用程序的路径,与wix一起安装.我尝试了以下方法:

<RegistryValue Root="HKLM" Key="Software\company\InstallLocation" Value="[#INSTALLLOCATION]" Type="string" Action="write" />
Run Code Online (Sandbox Code Playgroud)

INSTALLLOCATIONWix中文件夹的目录ID 在哪里,但这不起作用.似乎[#id]语法仅适用于文件...

我看到了以下问题,但他所引用的博客似乎已不复存在:

/sf/ask/36527781/

directory registry wix reference

30
推荐指数
1
解决办法
1万
查看次数

让cmake在没有包装脚本的情况下构建源代码?

我正在尝试让cmake构建到一个目录'build',就像project/buildCMakeLists.txt所在的那样project/.

我知道我能做到:

mkdir build
cd build
cmake ../
Run Code Online (Sandbox Code Playgroud)

但这很麻烦.我可以把它放在一个脚本中并调用它,但是为cmake提供不同的参数(比如-G"MSYS Makefiles")是不愉快的,或者我需要在每个平台上编辑这个文件.

我最好在主CMakeLists.txt中执行类似SET(CMAKE_OUTPUT_DIR构建)的操作.请告诉我这是可能的,如果是的话,怎么样?或者其他一些源代码构建方法可以很容易地指定不同的参数?

configuration cmake

25
推荐指数
3
解决办法
2万
查看次数

如何协调将头/源与模板分离的C++习惯用法?

我想知道这个模板业务.

在C和C++中,将声明放在源文件中的头文件和定义中是很常见的,并将两者完全分开.然而,在模板方面,这似乎不可能(以任何好的方式),而且众所周知,模板是一个很好的工具.

此外,Boost主要是标题,所以这是一个真正的问题.在C++中分离标题和源代码仍然是一个好主意,还是我不应该非常依赖模板?

c++ templates header

21
推荐指数
2
解决办法
2253
查看次数

不寻常的C++链接器错误 - '在丢弃的部分中定义'

我试图链接我的程序可执行文件,但我一直在收到错误.

boost::this_thread::sleep(boost::posix_time::milliseconds(10));
Run Code Online (Sandbox Code Playgroud)

在我的源代码中,链接器中产生以下错误:

`.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<std::runtime_error>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED2Ev[_ZN5boost16exception_detail19error_info_injectorISt13runtime_errorED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED1Ev[non-virtual thunk to boost::exception_detail::error_info_injector<boost::gregorian::bad_day_of_month>::~error_info_injector()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED2Ev[_ZN5boost16exception_detail19error_info_injectorINS_9gregorian16bad_day_of_monthEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev' referenced in section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED1Ev[non-virtual thunk to boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::gregorian::bad_year> >::~clone_impl()]' of /usr/local/lib/libboost_thread.a(thread.o): defined in discarded section `.text._ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED2Ev[_ZN5boost16exception_detail10clone_implINS0_19error_info_injectorINS_9gregorian8bad_yearEEEED5Ev]' of /usr/local/lib/libboost_thread.a(thread.o)
`.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED2Ev' referenced in section `.text._ZN5boost16exception_detail19error_info_injectorINS_9gregorian8bad_yearEED1Ev[non-virtual thunk …
Run Code Online (Sandbox Code Playgroud)

c++ linker c++11

18
推荐指数
2
解决办法
2万
查看次数

我应该为项目使用相对包含路径,还是将include-directory放在包含路径上?

在我的项目中,我目前使用相对路径来包含我的文件,这些文件肯定不会经常更改.但是,它会产生非常奇怪的包含模式,因为我通常将我的文件嵌套在很多文件夹中.

例如,在我目前的项目中network/server/myfile.hpp.它需要包括common/log.hpp.目前我使用的#include "../../common/log.hpp"是非常详细,但有效.

如果我改为在路径上添加我的主要包含目录,我可以简单地包括"common/log.hpp".

我知道这个问题可能更多是关于偏好而不是其他任何问题,但是关于跨平台应用程序有什么客观的利弊,那么C++约定呢?

c++ convention relative-path include

15
推荐指数
2
解决办法
1万
查看次数

std :: bind是否一般只使用move-only类型,特别是std :: unique_ptr?

我正在尝试使用boost :: asio并遇到一些泥潭.

我正在尝试编译以下代码:

std::unique_ptr<buffer_t> buffer = buffers.pop();
std::function<void(const boost::system::error_code&, size_t)> t = std::bind(&tcp_client::handle_read_done,
                                                                            this,
                                                                            std::placeholders::_1,
                                                                            std::placeholders::_2,
                                                                            std::move(buffer));
Run Code Online (Sandbox Code Playgroud)

如果我排除std :: move(缓冲区),当然从handle_read_done的签名和std :: bind中的传递参数,一切正常.

当试图将它传递给boost :: asio :: async_read_some时,它抱怨从std :: bind返回的对象上隐式删除的函数,对元组上的已删除函数,我假设是因为可移动性,以及大量的提升具体错误.如果我只是尝试将它分配到一个std :: function,它应该与提升调用的签名匹配,我得到那些相同的元组错误,所以我猜它们是相同的.只需将std :: bind的结果赋值给auto就不会产生编译错误,但当然我不能在其上调用任何东西.

我究竟做错了什么?以下是尝试分配时的输出std::function<void(const boost::system::error_code&,size_t)>

/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional: In static member function ‘static void std::_Function_handler<void(_ArgTypes ...), _Functor>::_M_invoke(const std::_Any_data&, _ArgTypes ...) [with _Functor = std::_Bind<std::_Mem_fn<void (rcon::net::tcp_client::*)(const boost::system::error_code&, long unsigned int, std::unique_ptr<std::array<unsigned char, 10240ul> >)>(rcon::net::tcp_client*, std::_Placeholder<1>, std::_Placeholder<2>, std::unique_ptr<std::array<unsigned char, 10240ul> >)>, _ArgTypes = {const boost::system::error_code&, long unsigned int}]’:
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.6.2/../../../../include/c++/4.6.2/functional:2148:6:   instantiated from ‘std::function<_Res(_ArgTypes …
Run Code Online (Sandbox Code Playgroud)

c++ bind unique-ptr c++11

11
推荐指数
1
解决办法
5325
查看次数

整齐地通过XAML填充IEnumerable?

我试图从XAML填充依赖属性.依赖属性是IEnumerable<KeyAction>KeyAction是复杂类型的位置.

<loc:MyType.KeyActions>
    <loc:KeyAction Action="Show" Key="Space" Modifiers="LeftCtrl" />
    <loc:KeyAction Action="Hide" Key="Escape" />
</loc:MyType.KeyActions>
Run Code Online (Sandbox Code Playgroud)

现在,这会导致KeyAction属性"声明两次",因为XAML会将每个项目解释为属性的候选项,而不是列表中的项目.

为此,它需要看起来像:

<loc:CompletionPopupView.KeyActions>
    <sys:List`KeyAction>
        <loc:KeyAction Action="Show" Key="Space" Modifiers="LeftCtrl" />
        <loc:KeyAction Action="Hide" Key="Escape" />
    </sys:List`KeyAction>
</loc:CompletionPopupView.KeyActions>
Run Code Online (Sandbox Code Playgroud)

而且我需要添加名称空间,如果可行的话,通用语法可能更加糟糕.有没有办法让第一个例子有效?

xaml .net-4.0

11
推荐指数
1
解决办法
3658
查看次数

不能将typeof(std :: endl)作为模板参数?

所以,我试图写一个这样的函数:

void append_to_stream(std::ostream &stream)
{ }

template <typename T, typename... Args>
void append_to_stream(std::ostream &stream, T first, Args&&... rest)
{
  stream << first;
  append_to_stream(stream, rest...);
}
Run Code Online (Sandbox Code Playgroud)

并称之为:

append_to_stream(stream, 
                 std::endl,
                 std::endl);
Run Code Online (Sandbox Code Playgroud)

但这不起作用.我收到一个错误,指出该函数的"参数太多".我把它缩小到我知道这std::endl是有罪的地步- 可能是因为它是一个功能.我设法通过声明一个被调用的结构来"解决"这个问题endl并定义<<operator它以便它只是调用它std::endl.这有效,但感觉不是特别好.是不是可以接受std :: endl作为模板参数?该功能适用​​于其他类型.

编辑:这是错误:

src/log/sinks/file_sink.cpp:62:21: error: too many arguments to function ‘void log::sinks::append_to_stream(std::string&, Args&& ...) [with Args = {}, std::string = std::basic_string<char>]’
Run Code Online (Sandbox Code Playgroud)

更新

试图让编译器推导出正确的模板参数@MooingDuck建议可以使用以下形式的函数:

  template<class e, class t, class a> 
  basic_ostream<e,t>&(*)(basic_ostream<e,t>&os) get_endl(basic_string<e,t,a>& s) 
  {
return std::endl<e,t>;
  }
Run Code Online (Sandbox Code Playgroud)

但是,这不编译.

错误:

src/log/sinks/file_sink.cpp:42:28: error: expected …
Run Code Online (Sandbox Code Playgroud)

c++ variadic-templates c++11

10
推荐指数
1
解决办法
1383
查看次数

找到是否有任何i以使array [i]等于i的算法

我的CS教授已经完成了一项任务:

在O(logn)时间内,如果在给定的预先排序的不同整数数组中找到索引i,则array [i] = i.证明时间是O(logn).

更新:整数可以是负数,0或正数.

好吧,所以我对此有点挣扎.我的想法是这样的:

使用二分搜索,我们只能确定中间元素左侧没有这样的值,如果array [mid] <= startindex,其中mid是中间元素的索引,startindex是数组的开头.

数组右半部分的对应规则是数组[mid]> = startindex + numel,其中变量如上所示,numel是中间右边的元素数.

这似乎不是O(logn),因为在最坏的情况下我必须遍历整个事情,对吗?有人能在这里向我说明正确的方向,还是告诉我这个有用吗?

我有什么想法可以正式证明这一点吗?我不是要求一个明确的答案,更多的帮助让我理解.

在C:

int _solve_prob_int(int depth, int start, int count, int input[])
    {
    if(count == 0)
        return 0;
    int mid = start + ((count - 1) / 2);
    if(input[mid] == mid)
        return 1;

    if(input[mid] <= start && input[mid] >= start + count)
        return 0;

    int n_sub_elleft = (int)(count - 1) / 2;
    int n_sub_elright = (int)(count) / 2;

    if(input[mid] <= start)
        return _solve_prob_int(depth …
Run Code Online (Sandbox Code Playgroud)

c arrays algorithm search

9
推荐指数
2
解决办法
2万
查看次数

Visual Studio 2010中的C++访问修饰符自动缩进慢慢让我发疯 - 可以改变吗?

在Visual Studio中编写C++时,它坚持在访问修饰符上给我这些神奇可怜的修正 - 如果有人真的喜欢这种方式,我表示哀悼;)(一个笑话人!)

public class MyClass
{
public:
   MyClass();
   ~MyClass();
   int wowAnInt();
}
Run Code Online (Sandbox Code Playgroud)

不用说,我想要这个:

public class MyClass
{
    public:
       MyClass();
       ~MyClass();
       int wowAnInt();
} 
Run Code Online (Sandbox Code Playgroud)

有没有办法用任何东西(我有Resharper和Highlighter)或者香草VS来实现这个目标?

c++ access-modifiers indentation visual-studio-2010

8
推荐指数
1
解决办法
1884
查看次数