头文件中的内联虚拟析构函数? [英] inline virtual destructor in a header file??

查看:52
本文介绍了头文件中的内联虚拟析构函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在头文件中的类,包含内联虚拟析构函数。

这样可以吗?可以造成任何问题吗?


班级基础

{

公开:

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屋!

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