This question is different from:
I wrote a class Test like this.
class Test {
private:
int *p;
public:
//constructor
Test(int i) {
p = new int(i);
}
Test & operator = (const Test &rhs) {
delete p;
p = new int(*(rhs.p));
return *this;
}
};
Run Code Online (Sandbox Code Playgroud)
When the parameter rhs of the operator function is itself (i.e. …
我有两个函数模板A和B.我在同一个文件中定义A然后定义B. 现在我想在A中打电话给B.我怎么能意识到这一点?正常功能原型在这种情况下不起作用.(请假设您无法更改A和B或拆分文件的顺序.)
#include <iostream>
template <class Type>
Type A(Type x) {
return 2 * B(x);
}
template <class Type>
Type B(Type x) {
return 3 * x;
}
int main() {
int x = 3;
std::cout << A(x) << "\n"; //=> ERROR
}
Run Code Online (Sandbox Code Playgroud)
来自g ++的错误:
test.cpp: In instantiation of ‘Type A(Type) [with Type = int]’:
test.cpp:40:21: required from here
test.cpp:29:17: error: ‘B’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of …Run Code Online (Sandbox Code Playgroud)