www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.gnu
digitalmars.D
digitalmars.D.bugs
digitalmars.D.dtl
digitalmars.D.dwt
digitalmars.D.announce
digitalmars.D.learn
digitalmars.D.debugger

C/C++ Programming
c++
c++.announce
c++.atl
c++.beta
c++.chat
c++.command-line
c++.dos
c++.dos.16-bits
c++.dos.32-bits
c++.idde
c++.mfc
c++.rtl
c++.stl
c++.stl.hp
c++.stl.port
c++.stl.sgi
c++.stlsoft
c++.windows
c++.windows.16-bits
c++.windows.32-bits
c++.wxwindows

digitalmars.empire
digitalmars.DMDScript

c++ - problem with enums in namespaces, and operator-> in templates

↑ ↓ ← 8irmer informatik.uni-hamburg.de writes:
Hi,

I tried out dm and encountered two problems.

1.) Declaration of enum constants in namespaces:

Example:

namespace storage {

enum type
{
dumb,
place,
pool,
heap
};
}

If i try to explicitely use these constants, like

unsigned int test = storage::heap;

-> error: namespace storage has no member heap

(while implicitely using them works ok, like

enum storage::type test = heap;

-> ok
)


2.) Problems with overriden operator->() in templates

If i have overriden the -> operator in a template class, and
i instantiate it with something where -> doesn't makes sense, i get an error
(even if i don't use the -> operator).
The dm compiler should only instantiate those templates which are really
needed, this would be more convenient. For example the gnu gcc and
visual c++ 7.0 doesn't complain, if you don't use the template
operator->()

class Test {
public:
double m;
}

smartptr<Test> p1;
p->m = 0.3;         // ok

smartptr<int> p2;  // ok if you don't use '->'


Best regards
Norbert Irmer
Nov 13 2002
↑ ↓ → Mac Reiter <reiter nomadics.com> writes:
8irmer informatik.uni-hamburg.de wrote:
 Hi,
 
 I tried out dm and encountered two problems.
 
 2.) Problems with overriden operator->() in templates
 
 If i have overriden the -> operator in a template class, and
 i instantiate it with something where -> doesn't makes sense, i get an error
 (even if i don't use the -> operator).
 The dm compiler should only instantiate those templates which are really
 needed, this would be more convenient. For example the gnu gcc and
 visual c++ 7.0 doesn't complain, if you don't use the template
 operator->()

Actually, I believe that it is more than just "more convenient". From what I can tell, the standard actually requires that unused template members _must_not_ be instantiated. I don't have the standard itself sitting around, but I've seen enough references to designs that rely on the non-instantiation that I feel relatively confident that it is in the standard.
 class Test {
 public:
 double m;
 }
 
 smartptr<Test> p1;
 p->m = 0.3;         // ok
 
 smartptr<int> p2;  // ok if you don't use '->'
 
 
 Best regards
 Norbert Irmer

Mac
Nov 13 2002