<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Interview - 标签 - 研发日志 · R&amp;D Log</title><link>https://rd163.visword.com/tags/interview/</link><description>Interview - 标签 - 研发日志 · R&amp;D Log</description><generator>Hugo -- gohugo.io</generator><language>zh-CN</language><managingEditor>whutluohui@gmail.com (小智晖)</managingEditor><webMaster>whutluohui@gmail.com (小智晖)</webMaster><copyright>本作品采用知识共享署名-非商业性使用 4.0 国际许可协议进行许可。</copyright><lastBuildDate>Thu, 08 May 2025 00:00:00 +0800</lastBuildDate><atom:link href="https://rd163.visword.com/tags/interview/" rel="self" type="application/rss+xml"/><item><title>C/C++面试基础知识</title><link>https://rd163.visword.com/posts/cpp-interview/</link><pubDate>Thu, 08 May 2025 00:00:00 +0800</pubDate><author><name>小智晖</name></author><guid>https://rd163.visword.com/posts/cpp-interview/</guid><description><![CDATA[<h2 id="cc-basics" class="headerLink">
    <a href="#cc-basics" class="header-mark"></a>C/C++ Basics</h2><h3 id="如何定义一个只能在堆上栈上生成对象的类" class="headerLink">
    <a href="#%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b9%89%e4%b8%80%e4%b8%aa%e5%8f%aa%e8%83%bd%e5%9c%a8%e5%a0%86%e4%b8%8a%e6%a0%88%e4%b8%8a%e7%94%9f%e6%88%90%e5%af%b9%e8%b1%a1%e7%9a%84%e7%b1%bb" class="header-mark"></a>如何定义一个只能在堆上（栈上）生成对象的类？</h3><blockquote>
  <p><a href="https://www.nowcoder.com/questionTerminal/0a584aa13f804f3ea72b442a065a7618" target="_blank" rel="noopener noreferrer">如何定义一个只能在堆上（栈上）生成对象的类?</a></p>

</blockquote><h4 id="只能在堆上" class="headerLink">
    <a href="#%e5%8f%aa%e8%83%bd%e5%9c%a8%e5%a0%86%e4%b8%8a" class="header-mark"></a>只能在堆上</h4><p>方法：将析构函数设置为私有</p>
<p>原因：C++ 是静态绑定语言，编译器管理栈上对象的生命周期，编译器在为类对象分配栈空间时，会先检查类的析构函数的访问性。若析构函数不可访问，则不能在栈上创建对象。</p>]]></description></item></channel></rss>