摘要: 摘自《Sun Studio 12: C++ 用户指南》 第 6.7.3 节模板在使用前必须先声明。一个友元声明构成了模板的使用,而非模板的声明。 (A friend declaration constitutes a use of the template, not a declaration of the template. )所以实际的模板声明必须在友元声明之前。例如,编译系统尝试链接以下示例中生成的目标文件时,对未实例化的operator<<函数,会生成一个未定义的错误。示例6–2 友元声明问题的示例// array.h// generates undefined error 阅读全文
posted @ 2011-12-17 13:35 MagiCube 阅读(516) 评论(0) 推荐(0) 编辑
摘要: 错误消息在函数“function”中引用了无法解析的外部符号“symbol”在 function 中找到了未定义的外部符号 (symbol)。若要解决此错误,请提供符号定义或移除引用它的代码。一般报错如下:error LNK2001: 无法解析的外部符号 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<c 阅读全文
posted @ 2011-12-17 13:27 MagiCube 阅读(820) 评论(0) 推荐(0) 编辑
摘要: 当授予对给定模板的实例的访问权时候,在作用域中不需要存在该类模板或函数模板的声明。实质上,编译器将友元声明也当作类或函数的声明对待(When we grant access to all instances of a given template, there need not be a declaration for that class or function template in scope. Essentially, the compiler treats the friend declaration as a declaration of the class or function 阅读全文
posted @ 2011-12-17 13:18 MagiCube 阅读(497) 评论(0) 推荐(0) 编辑