gpt4 book ai didi

c++ - 矩形 w(Origin(), Extents()) 和矩形 w2(o, e) 之间的区别

转载 作者:太空宇宙 更新时间:2023-11-04 12:12:35 25 4
gpt4 key购买 nike

// t1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

struct Origin
{
Origin(int _x=0, int _y=0) : x(_x), y(_y) {}
int x;
int y;
};

struct Extents
{
Extents(int _width=0, int _height=0) : width(_width), height(_height) {}
int width;
int height;
};
class Rectangle
{
public:
Rectangle(const Origin& o, const Extents& e) : m_origin(o), m_extents(e) {}

Origin m_origin;
Extents m_extents;
};

int _tmain(int argc, _TCHAR* argv[])
{
Rectangle w(Origin(), Extents()); // declare a function 'w'

Origin o(1, 2);
Extents e(3, 4);
Rectangle w2(o, e); // define a variable 'w2'

return 0;
}

问题> 正如我们所见,w 是一个函数的声明。 w2 是一个变量的定义。从编译器或语言的角度来看,使它们不同的关键区别是什么?

最佳答案

主要区别在于OriginExtends类型,而oe变量,不能解释为类型。

关于c++ - 矩形 w(Origin(), Extents()) 和矩形 w2(o, e) 之间的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9216962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com