-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
请教3.2章中两个问题 #63
Comments
同问: /opt/compiler-explorer/gcc-12.2.0/bin/../lib/gcc/x86_64-linux-gnu/12.2.0/../../../../x86_64-linux-gnu/bin/ld: /tmp/ccdgLfcf.o: in function `doSomething()':
<source>:31: undefined reference to `void inc_counter<unsigned int>(unsigned int&, std::enable_if<std::is_integral<unsigned int>::value, void>::type*)'
collect2: error: ld returned 1 exit status
Compiler returned: 1
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
我之前对template这部分内容了解不多,这份教程对我帮助很大!
但是在3.2章里面有两个地方没有搞明白,希望能得到一些指点。
第一个问题:
这里基类
ICounter
是个无用的tag,但是在inc_counter(static_cast<ICounter&>(cntObj)); // 2
中,将cntObj
转为ICounter
后,基类里并没有increase()
这个函数呀。要怎么实现计数的功能呢?所以这个地方没有理解。
第二个问题
仍是上面这份代码里的
inc_counter(static_cast<ICounter&>(cntObj)); // 2
,想要调用的应该是这个函数吧?但是这样会报错(用c++11/c++14都试过,估计与c++标准的版本无关):
请问这里是想要表达为:
还是直接:
另外,为什么会有这样的报错,我也不是很确定。
望指教,非常感谢!
The text was updated successfully, but these errors were encountered: