|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我在编程的时候突然遇到了这个问题:
注意到,在第85行处,代码的自动高亮消失了一部分,但是 Intellisense 无报错和警告,我很不能理解,这是为什么?怎么解决?
以下是我这个文件的完整代码:
- #pragma once
- namespace shape
- {
- template <typename number = int>
- class Dot
- {
- public:
- number x = 0;
- number y = 0;
- Dot() = default;
- Dot(number x, number y)
- {
- this->x = x;
- this->y = y;
- };
- };
- template <typename number = int>
- class Rect
- {
- public:
- Dot<number> position;
- number width = 0;
- number height = 0;
- Rect() = default;
- Rect(const number width, const number height, const Dot<number> position = {})
- {
- this->width = width;
- this->height = height;
- this->position = position;
- this->no_negative_size();
- };
- Rect(const Dot<number> from, const Dot<number> to = from)
- {
- this->position = from;
- this->width = to.x - from.x;
- this->height = to.y - from.y;
- this->no_negative_size();
- };
- inline Dot<number> get_absolute(Dot<number> relative)
- {
- return Dot<number>(relative.x + this->position.x, relative.y + this->position.y);
- };
- Dot<number> get_absolute(const choice::relative_pos relative) const
- {
- if (!((relative & choice::relative_pos::Center) && (relative & choice::relative_pos::Middle)))
- {
- throw error::ChoiceError();
- };
- Dot<number> result;
- if (relative & choice::relative_pos::Left)
- {
- result.x += this->position.x;
- };
- if (relative & choice::relative_pos::Right)
- {
- result.x += this->position.x + this->width;
- };
- if (relative & choice::relative_pos::Top)
- {
- result.y += this->position.y;
- };
- if (relative & choice::relative_pos::Bottom)
- {
- result.y += this->position.y + this->height;
- };
- if (relative & choice::relative_pos::Center) // Includes Left & Right
- {
- result.x /= 2;
- };
- if (relative & choice::relative_pos::Middle) // Includes Top & Bottom
- {
- result.y /= 2;
- };
- return result;
- };
- inline void set_absolute(const Dot<number> relative, const Dot<number> absolute)
- {
- this->position.x = absolute.x - relative.x;
- this->position.y = absolute.y - relative.y;
- };
- inline void set_absolute(const choice::relative_pos relative, Dot<number> absolute)
- {
- this->set_absolute(this->get_absolute(relative), absolute);
- };
- protected:
- inline void no_negative_size()
- {
- if (this->width < 0)
- {
- this->width = 0;
- };
- if (this->height < 0)
- {
- this->height = 0;
- };
- };
- };
- };
复制代码
其中引用到了"choice"和"error"命名空间,其来源分别在这里:
- namespace choice
- {
- enum relative_pos
- {
- Left = 0b0001,
- Right = 0b0010,
- Top = 0b0100,
- Bottom = 0b1000,
- Center = Left | Right,
- Middle = Top | Bottom
- };
- };
复制代码- namespace error
- {
- class BasicError : public std::exception
- {
- public:
- std::string reason;
- BasicError() = default;
- BasicError(std::string reason)
- {
- this->reason = reason;
- };
- };
- class ChoiceError : public BasicError {};
- };
复制代码 |
|