visual Ambiguous statements c++ -AMP:(extent)是不明确的

visual Ambiguous statements C++-AMP: (extent) is ambiguous

本文关键字:extent 不明确 Ambiguous statements c++ -AMP visual      更新时间:2023-10-16

我试图在c++ -AMP中编写代码,将多个2D矢量复制到GPU内存中进行处理。然而,一旦我从表达式extent<2> eM(100,100);开始,我就会遇到这个错误:"范围"是模糊的。是否与c++中的其他extent表达式有冲突?是因为我使用的库吗?这些是我包含的所有库和命名空间,我不能包含代码,因为它很长,会让人困惑。

#include "stdafx.h"
#include <Windows.h>
#include <stdint.h>
#include <amp.h>
#include <Shlwapi.h>
#include <vector>
#include <random>
#include <iostream>
using std::endl;
using std::cout;
#include <iomanip>
#include "timer.h"
#include <fstream>
using std::ifstream;
#include <cstring>
#include <sstream>
#include <tchar.h>
using namespace std;
using namespace concurrency;
using std::vector;

该消息意味着编译器无法判断您是想要std::extent还是concurrency::extent。有三种方法可以解决这个问题:

  • 删除#include带来的std::extent -这是不太可能是一个很好的解决方案,因为你可能需要的东西从头
  • 使用concurrency::extent时使用其全名-尴尬,但会工作
  • 删除using namespace std;并将其替换为单个语句,如using std::endl;,如您在#include语句中看到的。

我最喜欢最后一个,虽然它需要更多的工作。找出需要哪些工具的最佳方法是删除using namespace std;并进行编译。错误消息将告诉您正在使用std中的哪些类型。