标签: visual-c++-2010

模板代码上的编译器堆栈溢出

在我自己的类型擦除迭代器上工作时,我遇到了一个问题,编译器(MSVC10)在此代码上发生了堆栈溢出崩溃:

struct base {};  //In actual code, this is a template struct that holds data
template<class category, class valuetype>  
    struct any;  //In actual code, this is abstract base struct
template<class basetype, class category, class valuetype> 
    struct from; //In actual code, this is function definitions of any

template<class valuetype>
struct any<void,valuetype>
{ void a() {} };
template<class category, class valuetype>  
struct any
    : public any<void,valuetype> //commenting this line makes it compile
{ void b() {} };        

template<class basetype, class valuetype>
struct …
Run Code Online (Sandbox Code Playgroud)

c++ templates visual-c++ visual-c++-2010

7
推荐指数
1
解决办法
831
查看次数

Visual C++ 2010致命错误C1083; 没有权限

对于大学的一个班级,教授为我们提供了一些我们要修改的骨架代码.当我尝试在Visual C++ 2010 Express(x86)中编译代码时,收到以下错误:

C:\Users\[username]\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.cpp : fatal error C1083: Cannot open compiler generated file: 'Release\.NETFramework,Version=v4.0.AssemblyAttributes.obj': Permission denied
Run Code Online (Sandbox Code Playgroud)

我登录的帐户具有相关文件的完全读写修改权限,我使用的是Windows 7(x64).为了使问题更加混乱,项目在调试模式下编译,但在发布模式下编译,教授指示我们使用它.

预先感谢您的任何帮助.

c++ visual-c++-2010

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

lambda表达式(MSVC++ vs g ++)

我有以下代码

#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>


int main()
{
  typedef std::vector<int> Vector; 
  int sum=0;
  Vector v;
  for(int i=1;i<=10;++i)
     v.push_back(i);

  std::tr1::function<double()>  l=[&]()->double{

    std::for_each(v.begin(),v.end(),[&](int n){sum += n; //Error Here in MSVC++});
    return sum;
     };

  std::cout<<l();
  std::cin.get();
}
Run Code Online (Sandbox Code Playgroud)

上面的代码产生错误,MSVC++ 10而它编译得很好g++ 4.5.产生的错误是1 IntelliSense: invalid reference to an outer-scope local variable in a lambda body c:\users\super user\documents\visual studio 2010\projects\lambda\lambda.cpp 19 46 lambda

那么,有没有其他方法可以访问外部作用域变量sum而无需在本地lambda表达式(内部std::for_each)中显式创建新变量?

g++ 4.5代码编译好.标准(n3000草案)是否说了什么?(我目前没有C++ - 0x(1x?)标准的副本)

c++ lambda visual-c++ visual-c++-2010 c++11

6
推荐指数
1
解决办法
3221
查看次数

如何在VC++ 6.0转换的VC++ 2010项目中使用iFileDialog?

我可以在VC++ 2010应用程序中使用FileSaveDialog(Common Item Dialog),如下所示:

IFileDialog *pFileDialog;
HRESULT hr = CoCreateInstance(CLSID_FileSaveDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pFileDialog));    
Run Code Online (Sandbox Code Playgroud)

但是,当我将此代码放入已从VC++ 6.0转换为VC++ 2010的项目中时,我收到以下错误:

"错误C2787:'IFileDialog':没有与此对象关联的GUID"

我还在IID_PPV_ARGS宏下浮动错误和浮动错误:

"_uuidof的操作数必须有一个类或枚举类型,其中指定了_declspec(uuid('...'))"

我没有在任一项目中使用公共语言运行时支持(/ clr).

如何将GUID与我的对象相关联?

windows com winapi visual-c++ visual-c++-2010

6
推荐指数
1
解决办法
4038
查看次数

C++,vs 2010中的模糊继承错误

在这个例子中我对多态性的应用有些麻烦.这个问题类似于我的上一个问题

C++,虚拟继承,奇怪的抽象类+克隆问题

有3个抽象类:

class A
{
public:
    virtual A  * copy () const = 0;
    virtual ~A() = 0;
};

A::~A(){}

class B
{
public:
    virtual B  * copy () const = 0;
    virtual ~B() = 0;
};

B::~B(){}

class C: virtual public A , public B 
{
public:
    virtual C  * copy () const = 0;
    virtual ~C() = 0;
};

C::~C(){}
Run Code Online (Sandbox Code Playgroud)

和两个使用虚拟继承的继承类

class D: virtual public A
{
public:
    virtual D  * copy () const {return new D …
Run Code Online (Sandbox Code Playgroud)

c++ covariance virtual-inheritance visual-c++ visual-c++-2010

6
推荐指数
1
解决办法
1220
查看次数

尝试创建shared_ptr时std :: make_shared()中的错误?

(使用Visual Studio 2010)我正在尝试在我的项目中创建现有类的shared_ptr(类是在std :: shared_ptr存在之前写的十年).该类采用非const指针指向另一个对象,它的空参数构造函数是私有的.

class Foobar {
public:
    Foobar(Baz* rBaz);

private:
    Foobar();
}
Run Code Online (Sandbox Code Playgroud)

当我尝试创建一个shared_ptr时,事情进展不顺利:

Baz* myBaz = new Baz();
std::shared_ptr<Foobar> sharedFoo = std::make_shared<Foobar>(new Foobar(myBaz));
Run Code Online (Sandbox Code Playgroud)

在VS2010上,这给了我

error C2664: 'Foobar::Foobar(const Foobar &)' : cannot convert parameter 1 from 'Foobar *' to 'const Foobar &'
3>          Reason: cannot convert from 'Foobar *' to 'const Foobar'
Run Code Online (Sandbox Code Playgroud)

由于某种原因,它似乎是调用复制构造函数Foobar而不是构造函数Baz*.

我也不确定这个cannot convert from 'Foobar *' to 'const Foobar'部分.我最好的解释是我的模板类型shared_ptr<Foobar>是错误的.我做了,shared_ptr<Foobar*>但这似乎是错的,我见过的所有例子都没有使该类型成为原始指针.

似乎shared_ptr<Foobar*>正确地编译所有内容,但是Foobar当所有内容shared_ptr都超出范围时,是否会阻止对象被正确删除?

编辑: …

c++ shared-ptr visual-c++-2010 make-shared c++11

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

这是VC++ 2010编译器的错误吗?

使用Visual Studio 2010 SP1:

#include <vector>

//namespace XXX {
  struct Test
  {
    bool operator==(const Test& r) const  { return true; }
  };
//}
//typedef XXX::Test Test;

template <typename T> inline bool operator!=(const T& l,const T& r) 
{ return !(l==r); }

int main()
{
  std::vector<Test> vt;
  std::vector<Test> vt2 = std::move(vt);
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我按原样编译上面的代码,它会失败并显示以下错误:

1>C:\apps\MVS10\VC\include\vector(609): error C2593: 'operator !=' is ambiguous
1>          C:\apps\MVS10\VC\include\xmemory(268): could be 'bool std::operator !=<_Ty,_Ty>(const std::allocator<_Ty> &,const std::allocator<_Ty> &) throw()'
1>          with
1>          [
1>              _Ty=Test
1>          ] …
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-2010 visual-c++ visual-c++-2010 c++11

6
推荐指数
1
解决办法
735
查看次数

在MS C++ vs Clang中移动语义

做了一些实验与移动语义与我创建了一个数组类型后,我很奇怪,为什么按值从方法返回而锵编译器elides副本一起时,微软的C++编译器调用移动的构造?

这是Clang的正确或错误行为吗?或正确的微软行为?

#include <algorithm>
#include <iostream>

template<typename T>
class Array {
    public:
    template<typename E>
    class ArrayIterator {
        public:
        ArrayIterator(Array<E>& elements, int index) : position_(index), elements_(elements) {
        }

        T& operator * () {
            return elements_[position_];
        }

        ArrayIterator& operator++ () {
            position_++;
            return *this;
        }

        ArrayIterator operator++ (int) {
            return ArrayIterator(elements_, ++position_);
        }

        bool operator != (ArrayIterator const & other) {
            return position_ != other.position_;
        }

        private:
        int position_;
        Array<E>& elements_;
    };
    typedef ArrayIterator<T> iterator;
    Array();
    explicit Array(int size);
    ~Array();
    Array(const Array& …
Run Code Online (Sandbox Code Playgroud)

c++ clang visual-c++ visual-c++-2010 move-semantics

6
推荐指数
1
解决办法
468
查看次数

无符号长的类型与Windows上的uint32_t和uint64_t不同(VS2010)

在Windows 7,32位下的Visual Studio 2010上,unsigned long似乎是uint32_t和uint64_t的不同类型.请参阅以下测试程序:

#include <stdint.h>
#include <stdio.h>

template<class T, class U>
struct is_same_type
{
    static const bool value = false;
};
template<class T>
struct is_same_type<T, T>
{
    static const bool value = true;
};

#define TO_STRING(arg)        TO_STRING_IMPL(arg)
#define TO_STRING_IMPL(arg)   #arg

#define PRINT_SAME_TYPE(type1, type2) printf("%s (size=%d) %s %s (size=%d)\n", \
    TO_STRING(type1), int(sizeof(type1)), \
    is_same_type<type1, type2>::value ? "==" : "!=", \
    TO_STRING(type2), int(sizeof(type2)))


int main(int /*argc*/, const char* /*argv*/[])
{
    PRINT_SAME_TYPE(uint32_t, unsigned long);
    PRINT_SAME_TYPE(uint64_t, unsigned long);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我希望它能打印出来 …

c++ visual-c++ visual-c++-2010

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

如果类继承自 2 个模板化父类,则调用不明确。为什么?

我有一个模板化类,它对作为模板参数给出的类执行操作。对于我的某些课程,我想将功能“分组”在一个课程中,以便调用者更轻松。事实上,代码看起来像这样(名称已更改):

template<typename T>
class DoSomeProcessing
{
public:
   process(T &t);
};

class ProcessingFrontEnd : public DoSomeProcessing<CustomerOrder>, public DoSomeProcessing<ProductionOrder>
{
};
Run Code Online (Sandbox Code Playgroud)

问题是,当我使用 CustomerOrder 作为参数调用 ProcessingFrontEnd::process 时,编译器会抱怨它。

我尝试在较小的测试应用程序中重现该问题。这是代码:

#include <vector>

class X : public std::vector<char>
        , public std::vector<void *>
{
};

int main(void)
{
X x;
x.push_back('c');
return 0;
}
Run Code Online (Sandbox Code Playgroud)

事实上,如果编译,微软的 VS2010 编译器会给出这个错误:

test.cpp
test.cpp(11) : error C2385: ambiguous access of 'push_back'
        could be the 'push_back' in base 'std::vector<char,std::allocator<char> >'
        or could be the 'push_back' in base 'std::vector<void *,std::allocator<void *> >'
test.cpp(11) : …
Run Code Online (Sandbox Code Playgroud)

c++ templates multiple-inheritance visual-c++-2010

5
推荐指数
1
解决办法
1746
查看次数