第一个问题以前看见讨论过,不过当时没遇到就没留意,迷惑:
我的
template<typename Type>
class Matrix
{......}定义和声明必须放在一起!拆开就有错!是为什么?
第二个问题在我得
template<typename Type>
class Matrix
{.....
void WritetoFile(ofstream &fout)//int i
{ ....}
.......
}
函数WritetoFile不能把输出文件流类对象ofstream &作为参数,但是换成int或者其他的基本类型,就好好的!
还有一点,把ofstream的对象放在函数体内也是可以得!为什么??
错误信息是:
error C2061: syntax error : identifier ofstream
第一个问题纯粹是编译器的问题,
现在的编译器不支持export关键字,所以必须写到一个头文件里。
第二个问题不知什么意思
第二个问题是没有引用对应的库文件。
#include <fstream>
#include <string>
晚了1步。。。。
:~
gz
第二个问题:
加一句:
typedef Type instantiated_type;
然后用:
instantiated_type 代替 Type。
不知道行不行。
我也碰到过这个问题
第一个问题
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=507
up
第二个问题,可能是“笔误”,你看看上下文有没有错误。
ofstream 是“流”,
而不是一般的类,当你把其作为一个参数传递时,就会引起编译时的编址的错误
以上所解仅供参考
在第二个问题中:
typedef basic_ofstream<char, char_traits<char> > ofstream;
typedef basic_string<char, char_traits<char>, allocator<char> >
string;
我想可能是模板在具体化为类的时候,编译器出了麻烦。