【问题标题】:visual studio 2010 express STL list compiler errorVisual Studio 2010 Express STL 列表编译器错误
【发布时间】:2010-09-01 22:26:36
【问题描述】:

我正在将一些代码从 linux 移植到 windows 并出现一些奇怪的错误。我有以下课程:

(标题)
RegionRectangle.h

#ifndef __RECTANGLE_H__
#define __RECTANGLE_H__
#include <iostream>
using namespace std;
class Rectangle
{
public:
    Rectangle(int x = 0,int y = 0,int width = 0,int height = 0, int threshold=0);
    int x();
    int y();
    int width();
    int height();
    void x(int);
    void y(int);
    void width(int);
    void height(int);
    void threshold(int);
    int threshold(void);
    friend ostream& operator<<(ostream& output, const Rectangle& r);
private:
    int _x;
    int _y;
    int _width;
    int _height;
    int _threshold;
};

#endif

(实现)

RegionRectangle.cpp

#include "RegionRectangle.h"

Rectangle::Rectangle(int myx,int myy, int mywidth, int myheight,int threshold)
{
    _x=myx;
    _y=myy;
    _width=mywidth;
    _height=myheight;
    _threshold=threshold;
}
int Rectangle::x(void)
{
    return _x;
}
int Rectangle::y(void)
{
    return _y;
}
int Rectangle::width(void)
{
    return _width;
}
int Rectangle::height(void)
{
    return _height;
}

void Rectangle::x(int x)
{
    _x=x;
}

void Rectangle::y(int y)
{
    _y=y;
}

void Rectangle::width(int width)
{
   _width=width;
}

void Rectangle::height(int height)
{
    _height=height;
}
void Rectangle::threshold(int thresh)
{
    _threshold=thresh;
}
int Rectangle::threshold(void)
{
    return _threshold;
}

ostream& operator&lt;&lt;(ostream& output, const Rectangle& p)
{
    output << "[ (" << p._x << "," << p._y << "," << p._width << "," << p._height << "), threshold: " << p._threshold << " ]";
    return output;
}

我有另一个头文件具有这样的功能:

bool hasKey( map<PageNumberSide, list<Rectangle> > myMap, PageNumberSide myKey);

我收到的错误消息是:

enter code here

这第三个参考文件确实包含 RegionRectangle.h 为什么这不起作用?

1> 实用程序.cpp 1>c:\documents and settings\ferru001\my documents\work\cira_svn\win32_cira\Utils.h(56): error C2923: 'std::list' : 'Rectangle' 不是参数 ' 的有效模板类型参数_Ty' 1> C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\wingdi.h(3989):见“矩形”的声明 1>c:\documents and settings\ferru001\my documents\work\cira_svn\win32_cira\Utils.h(60): error C2923: 'std::list' : 'Rectangle' 不是参数 ' 的有效模板类型参数_Ty' 1> C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\wingdi.h(3989):见“矩形”的声明

【问题讨论】:

  • 请正确格式化您的代码,而不是尝试使用 HTML 标记(这在此处不起作用)。具体来说,使用工具栏上的“0101”按钮将代码标记为代码,并且&amp;lt;&amp;gt;引用为&amp;lt;&amp;gt;
  • 还有什么是编译器错误?
  • 1> Utils.cpp 1>c:\documents and settings\ferru001\my documents\work\cira_svn\win32_cira\Utils.h(56): error C2923: 'std::list' : 'Rectangle' 不是参数'_Ty' 1> C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\wingdi.h(3989) 的有效模板类型参数:请参阅'Rectangle' 1>c 的声明:\documents and settings\ferru001\my documents\work\cira_svn\win32_cira\Utils.h(60): error C2923: 'std::list' : 'Rectangle' 不是参数'_Ty'的有效模板类型参数
  • 您可以编辑您的问题以包含该文本以供参考。

标签: c++ visual-studio-2010 stl


【解决方案1】:

关键是:

C:\Program Files\Microsoft SDKs\Windows\v7.0A\include\wingdi.h(3989) : 见“矩形”的声明

编译器认为您指的是wingdi.h 中的Win32 SDK Rectangle 函数,而不是您刚刚定义的那个。我建议重命名您的矩形(或放入命名空间)并看看会发生什么。

【讨论】:

  • 非常感谢,我显然没有仔细看错误信息...已经工作了12个小时 :) 非常感谢您的帮助
猜你喜欢
  • 1970-01-01
  • 2015-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-15
相关资源
最近更新 更多