头文件中的内联虚拟析构函数? [英] inline virtual destructor in a header file??
问题描述
我在头文件中的类,包含内联虚拟析构函数。
这样可以吗?可以造成任何问题吗?
班级基础
{
公开:
base() {}
virtual~base {std :: cout<<" Inside virtual destructor \\\
" ;; }
//其他会员
};
" qazmlp" < QA ******** @ rediffmail.com>在留言中写道
news:db ************************** @ posting.google.c om ...我在头文件中的类,包含内联虚拟析构函数。
这可以吗?可以引起任何问题吗?
班级基地
{
公开:
base(){}
virtual~base {std :: cout<< ;Inside virtual destructor\\\
; }
//其他成员
};
这很好,实际上很常见。为什么不行呢?
john
qazmlp写道:我的类在头文件中,包含内联虚拟析构函数。
这样可以吗?可以引起任何问题吗?
班级基地
{
公开:
base(){}
virtual~base {std :: cout<< ;Inside virtual destructor\\\
; }
//其他成员
};
如果将函数声明为内联函数并不意味着编译器
*有*内联代码 - 这通常不适用于虚拟
函数 - 你只是'建议''他*可以*内联它。所以这就是
吧......
qazmlp写道:我的类在头文件中,包含内联虚拟析构函数。
这样可以吗?它可以导致任何问题吗?
它不可能。是什么让你担心呢?
-
祝你好运,
Andrey Tarasevich
My class in a header file, contains inline virtual destructor.
Is this Ok? Can it cause any problems?
class base
{
public:
base() { }
virtual ~base { std::cout<<"Inside virtual destructor\n"; }
// Other members
};
"qazmlp" <qa********@rediffmail.com> wrote in message
news:db**************************@posting.google.c om...My class in a header file, contains inline virtual destructor.
Is this Ok? Can it cause any problems?
class base
{
public:
base() { }
virtual ~base { std::cout<<"Inside virtual destructor\n"; }
// Other members
};
It''s fine, in fact its common. Why shouldn''t it be OK?
john
qazmlp wrote:My class in a header file, contains inline virtual destructor.
Is this Ok? Can it cause any problems?
class base
{
public:
base() { }
virtual ~base { std::cout<<"Inside virtual destructor\n"; }
// Other members
};
If you declare a function as inline it doesn''t mean that the compiler
*has* to inline that code - which usually wouldn''t work with virtual
functions - you just ''suggest'' that he *could* inline it. So it''s all
right with that...
qazmlp wrote:My class in a header file, contains inline virtual destructor.
Is this Ok? Can it cause any problems?
It can''t. What excactly makes you to worry about it?
--
Best regards,
Andrey Tarasevich
这篇关于头文件中的内联虚拟析构函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!