473,395 Members | 1,532 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.

Is this a abstract classe

Q 1. I defined a class with 10 functions . It contains declaration of 5

functions and 5 functions are declared and defined. Is this class is
said to a abstract class ?

Q 2. Which one is correct?

If a class contains a virtual class then it is said to a abstract
class ?
Or a abstract class always contains a virtual function ?
Or neither is true ?

Please clarrify me these.
------------------
I know that a class containing the pure virtual function is always a
abstract
class but I am confused with class containing the virtual functions.
-------------------

Mar 8 '06 #1
4 2315

sudhir wrote:
Q 1. I defined a class with 10 functions . It contains declaration of 5

functions and 5 functions are declared and defined. Is this class is
said to a abstract class ?

Q 2. Which one is correct?

If a class contains a virtual class then it is said to a abstract
class ?
Or a abstract class always contains a virtual function ?
Or neither is true ?

Please clarrify me these.
------------------
I know that a class containing the pure virtual function is always a
abstract
class but I am confused with class containing the virtual functions.
-------------------


A class is said to be abstract if and only if it contains at least one
pure virtual function.
And in any other case a class is not abstract.

Mar 8 '06 #2
Sunil Varma wrote:
[..]
A class is said to be abstract if and only if it contains
.... or inherits ...
at least one
pure virtual function.
And in any other case a class is not abstract.


V
--
Please remove capital As from my address when replying by mail
Mar 8 '06 #3

"sudhir" <su*****************@gmail.com> wrote in message
news:11*********************@j33g2000cwa.googlegro ups.com...
Q 1. I defined a class with 10 functions . It contains declaration of 5

functions and 5 functions are declared and defined. Is this class is
said to a abstract class ?
If one of the functions (methods) is pure virtual, then the class is
abstract, other wise it isn't. If it inherits a pure virtual function it's
abstract, otherwise it isn't.

An abstract class is defined as a class with at least one pure virtual
method. That's the definition. If the class doesn't have at least one pure
virtual method (or inherit one) then it's not abstract.
Q 2. Which one is correct?

If a class contains a virtual class then it is said to a abstract
class ?
Only if it's pure virtual.
Or a abstract class always contains a virtual function ?
Only if it's pure virtual.
Or neither is true ?
If either case is pure virtual.
I know that a class containing the pure virtual function is always a
abstract
class but I am confused with class containing the virtual functions.


An abstract class is a class that can not be instatized. It can't be
instantized, becuase it contains at least one pure virutal method.

The following compiles. Comment out that one line and it won't because of a
linking error.

class MyClass
{
public:
MyMethod() {};
MyMethod2();
};

int main()
{
MyClass MyInstance;
// Uncomment the following line and it won't compile
// MyInstance.MyMethod2();
}

Why does this compile? Because the compiler doesn't know where MyMethod2()
is defined. It waits for the linker to do that. The linker never sees any
call to MyMethod2() so it doesn't even try to link it. It works. When
MyMethod2() is called, however, then there's a linking error.

If, however, MyMethod2 was pure virtual it wouldn't compile because it's an
abstract class.

So an abstract class is a class that has at least one pure virtual method.
Mar 8 '06 #4
Thanks for such a nice solution....

I want to ask some more questions..

The pure virtual function is defined as ..

virtual void sum()=0;

then
Is this a pure virtual function ..
virtual void sum() {}

In above example...

class MyClass
{
public:
MyMethod() {};
MyMethod2();

};
int main()
{
MyClass MyInstance;
// Uncomment the following line and it won't compile
// MyInstance.MyMethod2();
}
MyMethod() {}; Is this a pure virtual function Or
MyMethod2(); It is pure virtual function

One more thing ... class Myclass is made a abstract class then how a
object creation is done on that...using Myclass MyInstance.

thanks

Mar 8 '06 #5

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

Similar topics

2
by: grigoo | last post by:
bonjour a tous je me presente a vous::: greg dit le grigoo sur le web ,,etudiant en bioinformatique a montreal et jusqu au cou dans notre language prefere....java. et biojava.. et je suis en un...
3
by: lamilla | last post by:
Salve a tutti, sto creando una applicazione che istanzia un thread al quale viene passato come argomento il puntatore ad una classe che contiene molte funzioni alcune delle quali devono essere...
1
by: Cloud Strife | last post by:
Salve ragazzi, qualcuno mi saprebbe indicare dove posso trovare i prototipi delle funzioni della classe string (magari se c'e' scritto come si usano e meglio^_^) ? please non mi dite di andare a...
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...
0
by: Alexandre Martins | last post by:
Pessoal, quero chamar um application do global.asax numa classe, tem como ??
1
by: sudhir | last post by:
I defined a class with 10 functions . It contains declaration of 5 functions and 5 functions are declared and defined. Is this class is said to a abstract class. Which one is correct? If a...
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: 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...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.