set / get in c ++。 [英] set/get in c++.
问题描述
嗨。
为了减少标题的大小并加入
变量的定义和内联函数的定义,我使用宏i看到
这个组包含所有内置类型和类型的赋值运算符。
#define ATRIBUTO(type,x)\
私人:\
类型x; \
公开:\
类型&获取## x(){return x; } \
类型获取## x(){return x; } const \
void设置## x(类型值){x =值; } \
A级{
ATRIBUTO(char,caracter);
};
1.-这个宏可能有缺陷吗?
2.-是否有任何解决方法,以便功能名称
扩展为名称在设置或获取资金后的第一个字母?,我
意味着:
GetCaracter和SetCaracter而不是Getcarater和Setcaracter。
我想在会员中使用caracter而不是Caracter
函数A.
提前谢谢你,原谅我的英文不好。
Manzanita写道:
嗨。
为了缩小我的体型
变量的标题和连接定义以及内联函数的定义,我使用我在这个组中看到的宏来获取具有赋值运算符的所有内置类型和类型。
#定义ATRIBUTO(type,x)\
private:\
输入x;公开:\
类型&获取## x(){return x; } \
输入## x(){return x; } const \
void设置## x(类型值){x =值; } \
A类{ATRIBUTO(char,caracter);
};
这是正式的我见过的这个
组中最糟糕的一个想法。
-Kevin
-
我的电子邮件地址有效,但会定期更改。
要联系我,请使用最近发布的地址。
" Manzanita" <在******** @ terra.es>在留言中写道
news:Xn ************************** @ 130.133.1.4 ...嗨。
为了减少我的标题的大小并加入
变量的定义和内联函数的定义,我使用了我在
中看到的宏这个组适用于具有赋值运算符的所有内置类型和类型。
#define ATRIBUTO(类型,x)\
私有:\
类型x;公开:\
类型&获取## x(){return x; } \
输入## x(){return x; } const \
void设置## x(类型值){x =值;分类A {
ATRIBUTO(char,caracter);
};
1.-这个宏可能有缺陷吗? / blockquote>
这样更好。
A级
{
公开:
字符;
};
但这非常糟糕,你的版本非常非常糟糕。我认为你需要
在面向对象的设计中做一些修改。
john
John哈里森写道:
[snip]但这非常糟糕,你的版本非常非常糟糕。我认为你需要在面向对象的设计中进行一些修改。
[snip]
我同意他的宏是丑陋(和坏代码),但我不确定是否有任何内在错误的get / set方法。我经常发现它们
非常有用。
当get / set方法与实现相关时出现问题
详细信息一对一的基础(如在宏观中)。
- Pete
Hi.
In order to reduce the size of my headers and join definitions of
variables and definitions of inline functions, i use a macro i saw in
this group for all built-in types and types with assignment operator.
#define ATRIBUTO( type, x) \
private: \
type x; \
public: \
type & Get##x() { return x; } \
type Get##x() { return x; } const \
void Set##x( type value ) { x = value; } \
class A{
ATRIBUTO(char, caracter);
};
1.- Can be flawed this macro?.
2.- Is there any workaround so that the names of the functions are
expanded to a name with the first letter following Set or Get capital?, i
mean:
GetCaracter and SetCaracter instead of Getcarater and Setcaracter.
I want to use caracter rather than Caracter inside the member
functions of A.
Thank you in advance and excuse my bad english.解决方案Manzanita wrote:
Hi.
In order to reduce the size of my headers and join definitions of
variables and definitions of inline functions, i use a macro i saw in
this group for all built-in types and types with assignment operator.
#define ATRIBUTO( type, x) \
private: \
type x; \
public: \
type & Get##x() { return x; } \
type Get##x() { return x; } const \
void Set##x( type value ) { x = value; } \
class A{
ATRIBUTO(char, caracter);
};
This is officially one of the worst ideas I''ve ever seen posted on this
group.
-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
"Manzanita" <in********@terra.es> wrote in message
news:Xn**************************@130.133.1.4...Hi.
In order to reduce the size of my headers and join definitions of
variables and definitions of inline functions, i use a macro i saw in
this group for all built-in types and types with assignment operator.
#define ATRIBUTO( type, x) \
private: \
type x; \
public: \
type & Get##x() { return x; } \
type Get##x() { return x; } const \
void Set##x( type value ) { x = value; } \
class A{
ATRIBUTO(char, caracter);
};
1.- Can be flawed this macro?.
This is better.
class A
{
public:
char character;
};
but this is very bad and your version is very, very bad. I think you need to
do some revision in object oriented design.
john
John Harrison wrote:
[snip]but this is very bad and your version is very, very bad. I think you need to
do some revision in object oriented design.
[snip]
I agree that his macro was ugly (and bad code), but I''m not sure there''s
anything intrinsically wrong with get/set methods. I often find them
quite useful.
The problem comes when the get/set methods are tied to implementation
details on a one-to-one basis (like in the macro).
-- Pete
这篇关于set / get in c ++。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!