小编A S*_*ity的帖子

在MSVC中对void*执行指针运算时出错

Error    1    error C2036: 'const void *' : unknown size    file.cpp     111
Run Code Online (Sandbox Code Playgroud)

我不跟随.GCC从不抱怨void*指针算法,即使是-ansi -pedantic -Wall.有什么问题?

这是代码 -

struct MyStruct {

    const void *buf;    // Pointer to buffer  
    const void *bufpos; // Pointer to current position in buffer

};

...

size_t    someSize_t, anotherSize_t;
MyStruct *myStruct = (MyStruct *) userdata;
...
  if ( (myStruct->bufpos + someSize_t) > 
       (myStruct->buf + anotherSize_t) ) { // Error on this line
     ...
Run Code Online (Sandbox Code Playgroud)

c++ windows void-pointers visual-c++

4
推荐指数
2
解决办法
4195
查看次数

在Visual C++中将std :: string添加到uint时出现模糊模板错误

我在Visual Studio 2008/Windows SDK 7上编译以下代码时出现以下错误

const UINT a_uint;
UINT result;

throw std::runtime_error( std::string("we did ") + a_uint +
                          " and got " + result );
Run Code Online (Sandbox Code Playgroud)

具有讽刺意味的是,我最终得到了这个结果

error C2782: 'std::basic_string<_Elem,_Traits,_Alloc> std::operator +(
                 const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem
             )' : template parameter '_Elem' is ambiguous
Run Code Online (Sandbox Code Playgroud)

有人可以解释为什么错误消息不能解释真正的问题(没有运算符来输入字符串)?

c++ templates operators visual-studio-2008 visual-c++

0
推荐指数
1
解决办法
1216
查看次数