473,382 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Inheriting from a typedef that is inside another class

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";
}
};

Jun 27 '08 #1
2 1393
On Sun, 25 May 2008 16:20:32 +0200, itaj sherman <it*********@gmail.com>
wrote:
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++

Jun 27 '08 #2
Hi!

Alf P. Steinbach schrieb:
<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
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: BCC | last post by:
Hi, A colleague has some code like this: class CMyObject { // Bunch of Member functions } class CMyObjectList: public std::vector<CMyObject> {
5
by: Azumanga | last post by:
I am trying to define a series of iterators for a container I am building, and as forward, bidirectional and random access iterators are very similar I thought it would be handy to put them into a...
2
by: Chris Foster | last post by:
Hi, I'm having some difficulty using types which are defined in a base class inside a derived class. The problem crops up using template classes. The following test code encapsulates what I'd...
7
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
7
by: for.fun | last post by:
Hi everybody, I have the following problem : B class need A::MyEnum type and A class need B::MyEnum type. In both case, the class type is incomplete so it is obvious that the ::MyEnum can not...
24
by: toton | last post by:
Hi, I want to have a vector like class with some additional functionality (cosmetic one). So can I inherit a vector class to add the addition function like, CorresVector : public...
3
by: toton | last post by:
Hi, If I inherit some template class to form another template class, do the member functions from the parent class automatically comes to the child class, or I need to write something like using...
13
by: miaohua1982 | last post by:
the code is as follows: #include <iostream> using namespace std; typedef double DOUBLE; class Screen { public: typedef int DOUBLE;
4
by: subramanian100in | last post by:
Consider the program #include <iostream> using namespace std; class Test { public: Test(Test_int c_value)
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.