r****t 发帖数: 10904 | 1 有这么一段 code,
#define NO_EXCEPTIONS
namespace MyNamespace {
class Location
{
public:
Location(const char *name);
Location() NO_EXCEPTIONS;
Location(const Location &);
Location & operator=(const Location & loc);
template
void read(const char *dataset_name, T & matrix) const {
MyNamespace::read(*this, dataset_name, matrix); //<<<<<< ERROR!
// Refer it to a non-member function
// so it can be overloaded even for classes
// | z***e 发帖数: 5393 | 2 no, namepspace没有virtual function;
而且也没看到你的MyNamespace::read在那里declare | r****t 发帖数: 10904 | 3 在 MyNamespace 里面加了几个空 function, (no, I added some declarations)
编译是过了,不知道有没有隐患。
【在 r****t 的大作中提到】 : 有这么一段 code, : #define NO_EXCEPTIONS : namespace MyNamespace { : class Location : { : public: : Location(const char *name); : Location() NO_EXCEPTIONS; : Location(const Location &); : Location & operator=(const Location & loc);
| r****t 发帖数: 10904 | 4 对,就是没有 declare, 但是老的 gcc 没问题,新的 gcc 就报错了,加了几个 empty
function, 看起来是编译过了。
【在 z***e 的大作中提到】 : no, namepspace没有virtual function; : 而且也没看到你的MyNamespace::read在那里declare
| t****t 发帖数: 6806 | 5 没明白, 你就是要调用mynamespace::read是不是? 没声明当然不能引用, 有什么奇怪
的吗?
【在 r****t 的大作中提到】 : 有这么一段 code, : #define NO_EXCEPTIONS : namespace MyNamespace { : class Location : { : public: : Location(const char *name); : Location() NO_EXCEPTIONS; : Location(const Location &); : Location & operator=(const Location & loc);
| r****t 发帖数: 10904 | 6 我那办法不顶用,我在别的地方想要 override mynamespace::read, 就出现错误
error: redefinition of ‘template void mynamespace::read(hid_....
I think I only decleard it, not define it, but I need to check...
那怎么老 gcc 就可以?这段本意是定义个 namespace, 里面 reference 到一个还没
declare 的 member function, 然后用户写程序根据需要来实现这个 member function
, 这在 gcc-2.95 work, 现在就不能用了,那么现在是怎么处理这种问题的呢?总不至
于都是用 subclass + virtual 吧?
【在 t****t 的大作中提到】 : 没明白, 你就是要调用mynamespace::read是不是? 没声明当然不能引用, 有什么奇怪 : 的吗?
| c*****s 发帖数: 385 | 7 Never heard of.Anything used in c++ must be defined.
One way you can do this is using
matrix.read(*this, dataset_name, matrix);
and define read in type T. This way you will pass compiler because T is
unknown at the time and it will assume it contains read function.
function
【在 r****t 的大作中提到】 : 我那办法不顶用,我在别的地方想要 override mynamespace::read, 就出现错误 : error: redefinition of ‘template void mynamespace::read(hid_.... : I think I only decleard it, not define it, but I need to check... : 那怎么老 gcc 就可以?这段本意是定义个 namespace, 里面 reference 到一个还没 : declare 的 member function, 然后用户写程序根据需要来实现这个 member function : , 这在 gcc-2.95 work, 现在就不能用了,那么现在是怎么处理这种问题的呢?总不至 : 于都是用 subclass + virtual 吧?
| t****t 发帖数: 6806 | 8 以前对template查得不严
现在template里面非dependent name一律都要先声明
function
【在 r****t 的大作中提到】 : 我那办法不顶用,我在别的地方想要 override mynamespace::read, 就出现错误 : error: redefinition of ‘template void mynamespace::read(hid_.... : I think I only decleard it, not define it, but I need to check... : 那怎么老 gcc 就可以?这段本意是定义个 namespace, 里面 reference 到一个还没 : declare 的 member function, 然后用户写程序根据需要来实现这个 member function : , 这在 gcc-2.95 work, 现在就不能用了,那么现在是怎么处理这种问题的呢?总不至 : 于都是用 subclass + virtual 吧?
| r****t 发帖数: 10904 | 9 I'll try this if things cannot work as they originally did. thank!
【在 c*****s 的大作中提到】 : Never heard of.Anything used in c++ must be defined. : One way you can do this is using : matrix.read(*this, dataset_name, matrix); : and define read in type T. This way you will pass compiler because T is : unknown at the time and it will assume it contains read function. : : function
| r****t 发帖数: 10904 | 10 我手上的 c++ primer 可能太老了,都没有讲到 dependent name.
【在 t****t 的大作中提到】 : 以前对template查得不严 : 现在template里面非dependent name一律都要先声明 : : function
|
|