'int'是在C ++标准库中定义的类吗? [英] Is 'int' a class defined in C++ standard library ?

查看:83
本文介绍了'int'是在C ++标准库中定义的类吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个非常简单的问题。是int

标准C ++库中的预定义类。如果是的话,它是否在某处以某种方式输入?我希望知道这个因为,我希望创建一个具有int的所有

功能的类,但也是从另一个基类派生的。

例如,


class Tuple:public Data,public int

{

元组()

{

;

}


~元组()

{< br $>
;

}

};


我肯定在这里遗漏了一些东西因为这给了

编译错误。有更好的方法吗?


先谢谢,

Vijay。

解决方案
>我有一个非常简单的问题。是int

标准C ++库中的预定义类。如果是的话,它是否在某处以某种形式输入?




不,它是一种内置类型每个c ++ - 编译器。




" Lord Labakudas" < 11 ******** @ yahoo.com>在消息中写道

news:d6 ************************** @ posting.google.c om ...



我有一个非常简单的问题。是int
标准C ++库中的预定义类。如果是的话,它是否在某处以某种方式输入?我希望知道这个,因为我希望创建一个具有int的所有功能的类,但也是从另一个基类派生的。
例如,
<类元组:公共数据,公共int
{元组()
{
;
}

〜元组()
{
;
}
};

我肯定在这里遗漏了一些东西,因为这会产生一个
编译错误。有没有更好的方法呢?

提前致谢,
Vijay。




" int"是类型的C ++ buit,而不是类或结构,你不能继承

它。 " INT"没有

运营商会员功能+, - 等,你可以覆盖,等等这些是

内置于语言

和你不能搞砸他们。 int没有typedef或头文件。


你想做什么?如果是元组是一种整数元组,你可以通过重载模拟

类的int操作,如+ - =等。即使你

可以继承

int,你仍然需要重新实现每个运营商。


我在猜,但是你可以通过在每个元组中拥有成员

变量来获得你想要的东西

int int(我正在压制元组是一些固定的有限集合
整数用于

的数学意义)


元组元组::运算符+ =(const元组及其他)

{

_t1 + = other._t1;

_t2 + = other._t2;


//等


返回* this;


}

其中_t1,_t2等是Tuple类的int成员变量。


如果您需要更多帮助,请发布更多信息。


dave



Dave Townsend发布:


拉巴库达斯勋爵 < 11 ******** @ yahoo.com>在消息中写道
新闻:d6 ************************** @ posting.google.c om ...



我有一个非常简单的问题。是int
标准C ++库中的预定义类。如果是的话,它是否在某处以某种方式输入?我希望知道这个,因为我希望创建一个具有int的所有功能的类,但也是从另一个基类派生的。
例如,

class Tuple:public Data,public int {
Tuple()
{
;
}

〜元组()
{
;
}
};

我肯定在这里遗漏了一些东西,因为这会产生一个
编译错误。有更好的方法吗?

先谢谢,Vijay。



" int"是类型的C ++ buit,而不是类或结构,你不能从它继承
。 " INT"没有
操作员成员函数+, - 等,你可以覆盖,等等这些
内置于语言
你不能搞乱它们。
int没有typedef或头文件。




你不能从内在类型继承。如果你真的想要,你可以用
写一个能够克隆它们的类,然后再做

类Blah:public IntrinsicClone< int>

{

我开了一个但从来没有完成......我想我忘了为什么我想要从一个内在的东西继承你的b $ b! />
-JKop


Hi,

I have a very simple question. Is int a predefined class in the
standard C++ library. If yes, is it typedef''d as int somewhere ? I
wish to know this because, I wish to create a class that has all the
functionalities of int, but is also derived from another base class.
For example,

class Tuple: public Data, public int
{
Tuple()
{
;
}

~Tuple()
{
;
}
};

I am definitely missing something here because this gives a
compilation error. Is there are better way to do this ?

Thanks in Advance,
Vijay.

解决方案

> I have a very simple question. Is int a predefined class in the

standard C++ library. If yes, is it typedef''d as int somewhere ?



No, it''s a type "built-in" with every c++-compiler.



"Lord Labakudas" <ll********@yahoo.com> wrote in message
news:d6**************************@posting.google.c om...

Hi,

I have a very simple question. Is int a predefined class in the
standard C++ library. If yes, is it typedef''d as int somewhere ? I
wish to know this because, I wish to create a class that has all the
functionalities of int, but is also derived from another base class.
For example,

class Tuple: public Data, public int
{
Tuple()
{
;
}

~Tuple()
{
;
}
};

I am definitely missing something here because this gives a
compilation error. Is there are better way to do this ?

Thanks in Advance,
Vijay.



"int" is a C++ buit in type, not a class or struct, you can''t inherit from
it. "int" doesn''t have
operator member functions +, - etc, which you can override, etc these are
built into the language
and you can''t mess with them. There is no typedef or header file for int.

What are you trying to do? If "Tuple" is a kind of tuple of integers, you
can emulate the
kind of int operations such as + - =, etc by overloading. Even if you
could inherit from
int, you would still have to reimplement each operator.

I''m guessing, but you could probably get what you want by having member
variables of
type int in each tuple ( I''m pressuming tuple is some fixed finite colletion
of integers used in
the mathematical sense)

Tuple Tuple::operator+=( const Tuple& other)
{
_t1 += other._t1;
_t2 += other._t2;

// etc

return *this;

}
where _t1 , _t2 etc are int member variables ot the Tuple class.

Post more info if you want more help.

dave




Dave Townsend posted:


"Lord Labakudas" <ll********@yahoo.com> wrote in message
news:d6**************************@posting.google.c om...

Hi,

I have a very simple question. Is int a predefined class in the
standard C++ library. If yes, is it typedef''d as int somewhere ? I
wish to know this because, I wish to create a class that has all the
functionalities of int, but is also derived from another base class.
For example,

class Tuple: public Data, public int {
Tuple()
{
;
}

~Tuple()
{
;
}
};

I am definitely missing something here because this gives a
compilation error. Is there are better way to do this ?

Thanks in Advance,
Vijay.



"int" is a C++ buit in type, not a class or struct, you can''t inherit
from it. "int" doesn''t have
operator member functions +, - etc, which you can override, etc these
are built into the language
and you can''t mess with them. There is no typedef or header file for
int.



You can''t inherit from the intrinsic types. If you really want to, you can
write a class that makes a clone of them and then do
class Blah : public IntrinsicClone<int>
{
I started one but never got around to finishing... I think I forgot why I
wanted to inherit from an intrinsic in the first place!
-JKop


这篇关于'int'是在C ++标准库中定义的类吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆