C++ 无法将变量从my.cpp传递到.h类?

C++ 无法将变量从my.cpp传递到.h类?,c++,pointers,pass-by-reference,C++,Pointers,Pass By Reference,我有以下设置 Square.h #ifndef square_h #define square_h #include "Shape.h" using namespace std; class Square : public Shape { public: Point * points = nullptr; int minX = 0; int maxX = 0;

我有以下设置

Square.h

#ifndef square_h
#define square_h
#include "Shape.h"
using namespace std;

class Square : public Shape
{
     public:
              Point * points = nullptr;
              int minX = 0;
              int maxX = 0;
              
              ...

              void getMinMax(Point *points, int minX, maxX)
}
# endif
Square.cpp

...

void Square :: getMinMax(Point *points, int minX, int maxX)
{
    this->minX = points[3].x;
}

...

string Square :: toString()
{
     cout << "Minimum X : " << minX << endl;
}
。。。
void Square::getMinMax(点*points,int-minX,int-maxX)
{
此->minX=点[3].x;
}
...
string Square::toString()
{
couttoString()
方法不返回任何内容。它应该返回字符串,而不是将其写入
cout
。执行
cout-toString();
时,将结果写入
cout

string Square::toString()
{
标准::stringstream ret;

ret我想我们需要看到更多的代码,我看不出你发布的任何东西有问题。你能把一个放在一起吗?我不清楚问题是什么。你显示的函数应该更改该对象中
minX
成员的值。很难说代码中会发生什么,但我们看不到。我看不到更多的问题发布嗨,我添加了更多与问题相关的代码片段(很抱歉,我现在无法生成一个可复制的示例)。当我运行程序,main.cpp将for循环运行到cout时,最小X将始终为0。您设置了
minX
,但输出了
minY
,对吗?如何调用
getMinMax
?当它只设置了一个成员变量时,为什么称它为
getMinMax
?真的,请创建一个来显示给我们看。还需要考虑一下一些时间来刷新,采取的SO,阅读,以及。
...

for(size_t i = 0; i < shapes.size(); i++)
{
    cout << shapes[i]->toString();
}
string Square :: toString()
{
    std::stringstream ret;
    ret << "Minimum X : " << minY << endl;
    return ret.str();
}