惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Project Zero
Project Zero
T
The Blog of Author Tim Ferriss
云风的 BLOG
云风的 BLOG
Recent Announcements
Recent Announcements
月光博客
月光博客
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
Last Week in AI
Last Week in AI
罗磊的独立博客
NISL@THU
NISL@THU
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Proofpoint News Feed
H
Help Net Security
L
LINUX DO - 最新话题
MongoDB | Blog
MongoDB | Blog
雷峰网
雷峰网
The Hacker News
The Hacker News
Apple Machine Learning Research
Apple Machine Learning Research
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Know Your Adversary
Know Your Adversary
Recent Commits to openclaw:main
Recent Commits to openclaw:main
S
Secure Thoughts
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
C
CERT Recently Published Vulnerability Notes
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
N
News and Events Feed by Topic
F
Full Disclosure
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
Recorded Future
Recorded Future
T
Threat Research - Cisco Blogs
博客园 - 三生石上(FineUI控件)
S
Securelist
T
The Exploit Database - CXSecurity.com
Forbes - Security
Forbes - Security
H
Hacker News: Front Page
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
V
Visual Studio Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tor Project blog
博客园 - 司徒正美
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org

核桃的炼金工坊

2023 韩国游记 C++23: Flat Containers Deducing This Stateful Metaprogramming 推し、燃ゆ Customization Point Object 2020 总结 搞了个 C++ 构建系统 软件设计哲学(NOTE) Paxos Note 关于 cpp 可见性的黑魔法后门 一个关于 private member function detect 的 SFINAE 模板 User-defined conversion and Copy elision VIM and Latex Compare Between CRTP and Virtual Interface in C++ Compile Time Reflection in C++11 C++11内存模型 在C++17中的部分新特性
Const Reference of Pointer
Hawtian Wang · 2018-01-17 · via 核桃的炼金工坊

问题起源: 在子类中实现一个模板父类的纯虚函数的时候,不能正确的通过编译。

template<typename T>
struct Fuck {
    virtual void shit(const T&) = 0;
}

shit函数接受一个常量引用,当我们使用一个指针类型(A*)来实例化这个模板类的时候,函数shit的类型就应该是:

void shit(const T&) = 0; <value T = A*>

当我尝试用下面这样的表示来实现这个函数的时候发生了编译错误:

struct FuckImpl : Fuck<A*> {
    void shit(const A*&) override;
}

这里正确的写法应该是:

struct FuckImpl : Fuck<A*> {
  void shit(A* const&) override;
};

这个问题大概由于const修饰符的结合性的问题,在前一种写法中const并没有修饰后面的引用,而是由于结合性的原因修饰了前面的指针。所以后一种写法中,const明确的修饰了后面引用。提供了正确的类型。


额外的吐槽:这里就要吐槽g++的报错了,我用clang编译的时候就给出了正确的表达式写法,只要抄上去就好了。2333