标准库的C 问题

C++ issue with standard library

本文关键字:问题 标准      更新时间:2023-10-16

我发表了这篇文章,因为我一生中的第一次是Visual Studio社区的难以理解的错误2017:

我根本无法在我的所有类中使用STD的其他成员,然后在Main.cpp中使用" Nullptr_t"。当我写下" std ::"时,Visual的自动完成仅暗示我" nullptr_t"。这是无法理解的。

main.cpp代码:

#include <SFML/Graphics.hpp>
int main()
{
    return 0;
}

点类代码:

#pragma once

class Point
{
private:
    float _x;
    float _y;
public:
    Point();
    Point(float x, float y);
    Point(const Point& p);
    ~Point();
    float getx() { return _x; }
    float gety() { return _y; }
    void setx(float x) { _x = x; }
    void sety(float y) { _y = y; }
};

/**********************************************************************************************************************************************/

#include "pch.h"
#include "Point.h"

Point::Point()
{
    _x = 0.0;
    _y = 0.0;
}
Point::Point(float x, float y)
{
    _x = x;
    _y = y;
}
Point::Point(const Point& p)
{
    _x = p._x;
    _y = p._y;
}
Point::~Point()
{
}

六边形类:

#pragma once

class Hexagon
{
private:
    Point _center;
    float _diameter;

public:
    Hexagon();
    Hexagon(Point center, float diameter);
    ~Hexagon();
};

/*****************************************************************************************************************************************************************************************

#include "pch.h"
#include "Hexagon.h"
#include "Point.h"

Hexagon::Hexagon() : _center()
{
    _diameter = 10;
}
Hexagon::Hexagon(Point center, float diameter) : _center(center)
{
    _diameter = diameter;
}
Hexagon::~Hexagon()
{
}

您只需要包含iostream库或添加此代码行,您需要它。

#include<iostream>