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

推荐订阅源

S
Security @ Cisco Blogs
Y
Y Combinator Blog
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
C
Check Point Blog
爱范儿
爱范儿
A
About on SuperTechFans
博客园 - 聂微东
V
Visual Studio Blog
博客园_首页
WordPress大学
WordPress大学
Help Net Security
Help Net Security
博客园 - Franky
Forbes - Security
Forbes - Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Webroot Blog
Webroot Blog
博客园 - 司徒正美
人人都是产品经理
人人都是产品经理
量子位
Vercel News
Vercel News
Google DeepMind News
Google DeepMind News
W
WeLiveSecurity
V
V2EX
SecWiki News
SecWiki News
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Securelist
L
LangChain Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Schneier on Security
Schneier on Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
The Register - Security
The Register - Security
L
Lohrmann on Cybersecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Privacy International News Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cyber Attacks, Cyber Crime and Cyber Security
Simon Willison's Weblog
Simon Willison's Weblog
Apple Machine Learning Research
Apple Machine Learning Research
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news
Spread Privacy
Spread Privacy
F
Full Disclosure
美团技术团队
I
Intezer

核桃的炼金工坊

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