473,395 Members | 1,377 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,395 software developers and data experts.

Abstract class

Hello!

I'm reading a book about C++ and there is something that I don't understand
so I ask you out there.
The book says "an abstact class has a complete interface and only provides
the implementation of operations that can be specified at this general
level. These implementations can use other operations defined in the class,
both concrete and abstract"

Now to my question this sentence "These implementations can use other
operations defined in the class, both concrete and abstract" is that really
right. Assume you have 5 methods in the abstract class and we call them
a,b,c,d,e and a,b and c are concrete so d and e are pure cirtual. Then when
you implement the concrete methods a,b and c in the abstact class can you
then use the abstact methods d or e.

Many thanks

//Tony
Jul 23 '05 #1
3 1646
Tony Johansson wrote:
Hello!

I'm reading a book about C++ and there is something that I don't understand
so I ask you out there.
The book says "an abstact class has a complete interface and only provides
the implementation of operations that can be specified at this general
level. These implementations can use other operations defined in the class,
both concrete and abstract"

Now to my question this sentence "These implementations can use other
operations defined in the class, both concrete and abstract" is that really
right. Assume you have 5 methods in the abstract class and we call them
a,b,c,d,e and a,b and c are concrete so d and e are pure cirtual. Then when
you implement the concrete methods a,b and c in the abstact class can you
then use the abstact methods d or e.

Many thanks

//Tony


yes, you can. The only situation where this is impossible is in the
constructor and destructor of your abstract class, because in the during
their execution all method calls are bound statically, as the object may
be already be constructed/destructed partially.

Tom
Jul 23 '05 #2
"Tony Johansson" wrote...
Hello!

I'm reading a book about C++ and there is something that I don't understand
so I ask you out there.
The book says "an abstact class has a complete interface and only provides
the implementation of operations that can be specified at this general
level. These implementations can use other operations defined in the class,
both concrete and abstract"

Now to my question this sentence "These implementations can use other
operations defined in the class, both concrete and abstract" is that really
right. Assume you have 5 methods in the abstract class and we call them
a,b,c,d,e and a,b and c are concrete so d and e are pure cirtual. Then when
you implement the concrete methods a,b and c in the abstact class can you
then use the abstact methods d or e.


Sure:

#include <iostream>

class Dog
{
public:
virtual void bark() =0; // pure virtual
void barkALot() // concrete
{
for (int i=0; i<10; ++i) bark();
}
};

class Peke : public Dog
{
public:
virtual void bark()
{
std::cout << "woof\n";
}
};

class GreatDane : public Dog
{
public:
virtual void bark()
{
std::cout << "WOOF\n";
}
};

int main()
{
Dog* pdog[3];
// pdog[0] = new Dog; --- error: Dog is abstract
pdog[1] = new Peke;
pdog[2] = new GreatDane;
pdog[1]->barkALot();
pdog[2]->barkALot();
delete pdog[1];
delete pdog[2];
return 0;
}

--
Lionel B

Jul 23 '05 #3
Thomas Maier-Komor wrote:
Tony Johansson wrote:
Hello!

I'm reading a book about C++ and there is something that I don't
understand so I ask you out there.
The book says "an abstact class has a complete interface and only
provides the implementation of operations that can be specified at this
general level. These implementations can use other operations defined in
the class, both concrete and abstract"

Now to my question this sentence "These implementations can use other
operations defined in the class, both concrete and abstract" is that
really right. Assume you have 5 methods in the abstract class and we call
them a,b,c,d,e and a,b and c are concrete so d and e are pure cirtual.
Then when you implement the concrete methods a,b and c in the abstact
class can you then use the abstact methods d or e.

Many thanks

//Tony


yes, you can. The only situation where this is impossible is in the
constructor and destructor of your abstract class, because in the during
their execution all method calls are bound statically, as the object may
be already be constructed/destructed partially.


Your claim is correct, but not the reason. The calls are not bound
statically. They still use polymorphism, but only up to the class that the
constructor that is currently being executed belongs to.

Jul 23 '05 #4

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

Similar topics

4
by: Tony Johansson | last post by:
Hello! Assume you have an abstract class called Body and a derived class called cylinder. When you have an abstract class you can't instansiate an object. As you can see in the abstract class...
12
by: Daedalus.OS | last post by:
Ok first I'm pretty new to OOP, so my question may sound stupid to some of you. If the only answer you can provide is "get a book about OOP" then don't loose your time and mine cause it's already...
2
by: Dave Veeneman | last post by:
Is is legal to declare abstract members in non-abstract classes? How about non-abstract members in abstract classes? I am writing a base class with three derived classes. The base class will...
6
by: Dan Sikorsky | last post by:
If we were to define all abstract methods in an abstract class, thereby making that class non-abstract, and then override the heretofore 'abstract' methods in a derived class, wouldn't that remove...
7
by: jason | last post by:
In the microsoft starter kit Time Tracker application, the data access layer code consist of three cs files. DataAccessHelper.cs DataAcess.cs SQLDataAccessLayer.cs DataAcccessHelper appears...
0
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
4
by: N.RATNAKAR | last post by:
hai, what is abstract class and abstract method
0
by: emin.shopper | last post by:
I had a need recently to check if my subclasses properly implemented the desired interface and wished that I could use something like an abstract base class in python. After reading up on metaclass...
4
by: David Zha0 | last post by:
Hi, "when we call a virtual method, the runtime will check the instance who called the method and then choose the suitable override method, this may causes the performance drop down", is this...
6
by: Miguel Guedes | last post by:
Hello, I recently read an interview with Bjarne Stroustrup in which he says that pure abstract classes should *not* contain any data. However, I have found that at times situations are when it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.