// 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;
}
Question> As we can see, w is the declaration of a function. w2 is the definition of a variable.
From the compiler or language point of view, what is the key difference that makes them different?
The key difference is that
OriginandExtendsare types, whileoandeare variables and cannot be interpreted as types.