在Visual C++(2008和2010)中,以下代码无法编译,并出现以下错误:
#include <memory>
void Foo( std::shared_ptr< int > test = ::std::make_shared< int >( 5 ) )
{
}
class P
{
void
Foo( std::shared_ptr< int > test = ::std::make_shared< int >( 5 ) )
{
}
};
Run Code Online (Sandbox Code Playgroud)
错误C2039:'make_shared':不是'`global namespace''的成员
错误C3861:'make_shared':找不到标识符
它抱怨P :: Foo()的定义不是:: Foo().
有人知道为什么Foo()有一个与std :: make_shared但不是P :: Foo()的默认参数有效吗?
我有一个程序,每当我最小化它,它就会进入系统托盘.
我想知道的是:a)当我的程序在系统托盘中时,我怎么能检测到按键.b)我怎么能知道他们在键盘上按下了什么功能按钮.
我有一个输入字符串"0100"
为什么scanf("%i", &n);返回64和cin >> n; 给我100?为什么cin以十进制值表示,scanf以八进制表示?
为什么std :: auto_ptr上不允许使用operator []?
#include <iostream>
using namespace std ;
template <typename T>
void foo( T capacity )
{
auto_ptr<T> temp = new T[capacity];
for( size_t i=0; i<capacity; ++i )
temp[i] = i; // Error
}
int main()
{
foo<int>(5);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在Microsoft Visual C++ 2010上编译.
错误:错误C2676:二进制'[':'std :: auto_ptr <_Ty>'未定义此运算符或转换为预定义运算符可接受的类型
我遇到了VS2010(和VS2008)的问题,给出了一个很好的语法错误列表.但是,语法确实是正确的.这是一个小例子;
我在.h文件中有以下代码块
// Prototype Declarations
LIST* createList (int (*compare) (void*, void*));
LIST* destroyList (LIST* plist);
int addNode (LIST* pList, void* dataInPtr);
bool removeNode (LIST* pList, void* keyPtr, void** dataOutPtr);
bool searchList (LIST* pList, void* pArgu, void** pDataOut);
bool retrieveNode (LIST* pList, void* pArgu, void** dataOutPtr);
bool traverse (LIST* pList, int fromWhere, void** dataOutPtr);
int listCount (LIST* pList);
bool isListEmpty (LIST* pList);
bool isListFull (LIST* pList);
Run Code Online (Sandbox Code Playgroud)
LIST是一个typedef'd结构,FYI.所有这些函数声明似乎都是正确的语法.然而,在尝试构建时,我从第一个bool函数开始,从列表中获取以下语法错误.
错误2错误C2059:语法错误:';'
我没有看到问题出在哪里.同样,这只是一个小例子.我还收到语法错误,如下所示
bool found;
Run Code Online (Sandbox Code Playgroud)
错误29错误C2065:'bool':未声明的标识符
我真的迷失了这个.这里发布的代码不是我自己的,它来自数据结构书,但它看起来也是正确的.任何帮助,将不胜感激.谢谢!
我发现以下代码不能在Visual Studio 2010中编译(但在GCC中可以正常工作):
using namespace std;
unique_ptr<string> up(new string("abc"));
auto bound = bind(&string::size, move(up));
bound();
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
'std :: unique_ptr <_Ty> :: unique_ptr':无法访问类'std :: unique_ptr <_Ty>'中声明的私有成员
是因为VS2010绑定实现不支持仅移动类型吗?
所有源文件似乎编译得很好.
但是,由于我实现了这一点,我得到一个新的编译器错误:
1>------ Erstellen gestartet: Projekt: OpenLieroX, Konfiguration: Debug Win32 ------
1>Der Buildvorgang wurde am 29.03.2012 23:57:39 gestartet.
1>InitializeBuildStatus:
1> Aktualisieren des Timestamps von "Debug\OpenLieroX.unsuccessfulbuild".
1>ClCompile:
1> Alle Ausgaben sind aktuell.
1> Alle Ausgaben sind aktuell.
1> Alle Ausgaben sind aktuell.
1> Alle Ausgaben sind aktuell.
1> Alle Ausgaben sind aktuell.
1> Alle Ausgaben sind aktuell.
1> Alle Ausgaben sind aktuell.
1> Alle Ausgaben sind aktuell.
1> Alle Ausgaben sind aktuell.
1> Alle Ausgaben sind aktuell.
1> Alle Ausgaben sind …Run Code Online (Sandbox Code Playgroud) c++ visual-studio-2010 visual-studio visual-c++ visual-c++-2010
VS2010
我有一个unique_ptr内部结构.然后,我有一个vector这种结构.如果我尝试调整向量(或使用reserve),我会收到编译错误.下面是一个精简的例子,仍然存在问题.
struct Test
{
unique_ptr<int> pValue;
};
void test()
{
// this doesn't compile
vector<Test> testVector;
testVector.resize(5);
// this also doesn't compile
testVector.reserve(5);
// this, of course, compiles
vector<unique_ptr<int>> testVector2;
testVector2.resize(5);
testVector2.reserve(5);
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是关于访问unique_ptr(赋值运算符)的私有成员的投诉.编译器正在尝试动态构造Test &Test::operator =(const Test &)和Test::Test(const Test &).我不明白为什么调整大小操作需要调用这些函数中的任何一个(为什么不调用默认构造函数,如果它需要?).他们都存在问题,因为它是不可能使要么unique_ptr因const.
我正在 Visual Studio 2010 Pro 中处理一个(非托管的)x64 Win32 C++ 应用程序,并且不断收到一个奇怪的链接错误。
此应用程序LoadImage()通过包含windows.h. 虽然应用程序在 Release 配置中编译得很好(并LoadImage()完成了它的工作),但我无法在 Debug 配置中链接可执行文件。我不断收到此错误:
Redacted.obj : error LNK2019: unresolved external symbol __imp_LoadImageW referenced in function "public: int __cdecl Redacted::Redacted::Execute(void)" (?Execute@Redacted@Redacted@@QEAAHXZ)
C:\Users\redacted\Documents\Visual Studio 2010\Projects\Redacted\x64\Debug\Redacted.exe : fatal error LNK1120: 1 unresolved externals
Run Code Online (Sandbox Code Playgroud)
如果我从 Unicode 切换到非多字节字符集,错误消息会相应地从 更改LoadImageW()为LoadImageA(),但否则会持续存在。由于我在 Release 和 Debug 配置的属性中找不到任何相关差异,我不知道为什么它会编译为一个,而不是另一个。在两种配置中都User32.lib正确设置为链接器的附加依赖项,并且/MACHINE:X64在两者中也设置了标志。
由于链接器不会抱怨找不到User32.lib,我相信它试图从 Platform SDK 链接错误的版本,即 32 位版本。但是我如何才能找出链接器实际尝试使用的 LIB 文件的确切副本?
我正在尝试编译一些在Arduino IDE中编译良好的代码,在Visual Studio中支持Arduino(Visual Micro).这是有问题的代码:
template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
const byte* p = (const byte*)(const void*)&value;
unsigned int i;
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
return i;
}
template <class T> int EEPROM_readAnything(int ee, T& value)
{
byte* p = (byte*)(void*)&value;
unsigned int i;
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
return i;
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误是:
app.ino:43:40: error: 'T' does not name a type
:int EEPROM_writeAnything(int ee, const …Run Code Online (Sandbox Code Playgroud) c++ arduino visual-studio visual-c++-2010 visual-studio-2015
visual-c++-2010 ×10
c++ ×7
visual-c++ ×4
c++11 ×2
arduino ×1
auto-ptr ×1
boolean ×1
c ×1
cin ×1
linker ×1
scanf ×1
templates ×1
unique-ptr ×1
vector ×1
winapi ×1