Inheriting from a typedef that is inside another class

I

itaj sherman

The following does not compile on my VC6. Is it standard?


#include <iostream>

class Base
{
public:
explicit Base()
{
std::cout << "Base:ctor()" << "\n";
}

};


class Scope
{
public:
typedef Base BaseInScope;
};



class Derived:
public Scope::BaseInScope
{
public:
explicit Derived()
:
Scope::BaseInScope()
{
std::cout << "Derived:ctor()" << "\n";
}
};


D:\code\Test\Test\Test.cpp(39) : error C2614: 'Derived' : illegal
member initialization: 'BaseInScope' is not a base or member



The following fixes the problem:


class Derived:
public Scope::BaseInScope
{
public:
typedef Scope::BaseInScope MyBase

explicit Derived()
:
MyBase()
{
std::cout << "Derived:ctor()" << "\n";
}
};


and also:


class Derived:
public Scope::BaseInScope
{
public:
explicit Derived()
:
Base()
{
std::cout << "Derived:ctor()" << "\n";
}
};
 
F

Frank Birbacher

Hi!
<quote>
Comeau C/C++ 4.3.10.1 (May 7 2008 20:26:48) for ONLINE_EVALUATION_BETA1
Copyright 1988-2008 Comeau Computing. All rights reserved.
MODE:strict errors C++ noC++0x_extensions


In strict mode, with -tused, Compile succeeded (but remember, the Comeau
online compiler does not link).
</quote>

In short this means "it is standard". :)

Well, I wonder what would do the "explicit" specification to the default
ctor? There isn't even a warning about it which makes me wonder if there
is any effect. Is there?

Frank
 
D

David Côme

The following does not compile on my VC6. Is it standard?
Change it for VS C++ 2008.
#include <iostream>

class Base
{
public:
explicit Base()
{
std::cout << "Base:ctor()" << "\n";
}

};


class Scope
{
public:
typedef Base BaseInScope;
};



class Derived:
public Scope::BaseInScope
{
public:
explicit Derived()
:
Scope::BaseInScope()
{
std::cout << "Derived:ctor()" << "\n";
}
};
compile perfectly with g++
 
I

itaj sherman

* Frank Birbacher:









The standard states that an "explicit" default constructor will be used to
perform to default initialization, so presumably "explicit" on a default
constructor has no effect whatsoever.

"explicit" on a copy constructor is more subtle.

Since I'm right back from my fav café having a beer in the sun, and is a bit
tired, I simply don't want to think about those subtleties... ;-)

Cheers, & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?- Hide quoted text -

- Show quoted text -

Thanks to you all.
Yes, the 'explicit' has no effect. It's just my custom to declare all
ctors explicit, and change that only if needed.
But it makes no difference for my problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top