我正在尝试用 C++-AMP 编写代码,将多个 2D vector 复制到 GPU 内存中进行处理。但是,一旦我开始使用表达式 extent<2> eM(100,100);
我遇到这个错误:“范围”不明确。是否与 C++ 中的任何其他范围表达式有任何冲突?是因为我使用的库吗?
这些是我包含的所有库和命名空间,我不能包含代码,它很长而且会造成混淆。
#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
。可以通过三种方法解决此问题:
- 删除引入
std::extent
的#include
- 这不太可能是一个好的解决方案,因为您可能需要该 header 中的内容 - 每次使用时都通过全名调用
concurrency::extent
- 笨拙,但会起作用 - 删除
using namespace std;
并将其替换为单独的语句,例如using std::endl;
,如您在#include
语句中所见.
我最喜欢最后一个,尽管它更费功夫。发现您需要其中哪一个的最佳方法是删除 using namespace std;
并编译。错误消息会让您知道您正在使用 std 中的哪些类型。
关于c++ - 歧义语句 C++-AMP : (extent) is ambiguous,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17169332/