由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - C++ namespace 弱问
相关主题
一个关于C++ template和overload的问题a simple question for C++ class
C++ linking 弱问 (one file)C++ Q04: template member
C++ template function typeC++ implicit typename的问题
C++ template question请问这是什么错误呀
[合集] 又被羞辱了一把... (转载)这段 C++ 怎么改才能编译?
谁给详细说一下这句一个C++ template的问题
问个c++的template的问题C++ template question
template 疑问tempalte as the overloaded conversion operator
相关话题的讨论汇总
话题: location话题: const话题: namespace话题: read
进入Programming版参与讨论
1 (共1页)
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

1 (共1页)
进入Programming版参与讨论
相关主题
tempalte as the overloaded conversion operator[合集] 又被羞辱了一把... (转载)
C++ template谁给详细说一下这句
a c++ question问个c++的template的问题
文一个简单的c++template 疑问
一个关于C++ template和overload的问题a simple question for C++ class
C++ linking 弱问 (one file)C++ Q04: template member
C++ template function typeC++ implicit typename的问题
C++ template question请问这是什么错误呀
相关话题的讨论汇总
话题: location话题: const话题: namespace话题: read