473,765 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2349

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******** *************@j 33g2000cwa.goog legroups.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.MyMe thod2();
}

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.MyMe thod2();
}
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
3032
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 newbee dans ce domaine et me dit que l homme est bien peu de chose voici en definitive mon probleme>>> je construit une classe appele symbolListWithGap. dans celle j y mets un constructeur:::: symbolListWithGap qui recoit
3
2627
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 necessariamente static. Non trovando nessun esempio in giro e non sapendo come referenziare le variabili globali di classe CIndiceSP nelle funzioni static della classe stessa ho utilizzato questo metodo che non mi crea nessun errore di compilazione...
1
2872
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 spulciare tra i file del dev (uso quello) perche non ci capisco molto altrimenti... In realtà dovrei fare un esame e il prof ha detto che ci possiamo portare delle librerie o i prototipi di funzioni (anche brevemente commentati) in maniera tale da...
2
9606
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 define the behavior for most, but not all of its members. The derived classes will define the behavior for the remaining members (the undefined members). I'd like to force the derived classes to implement the undefined members in the base class. I...
6
5803
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 the need to have abstract class types in C#? Derived classes from abstract base classes must overrided the abstract method defininition anyway, so why not just provide a complete definition for the abstract method when defining the containing...
0
1109
by: Alexandre Martins | last post by:
Pessoal, quero chamar um application do global.asax numa classe, tem como ??
1
335
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 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.
7
4474
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 to be checking that the correct data type is used DataAcess sets an abstract class and methods
0
2834
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 magic, I wrote the following module. It is mainly useful as a light weight tool to help programmers catch mistakes at definition time (e.g., forgetting to implement a method required by the given interface). This is handy when unit tests or...
0
9568
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10163
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9957
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7379
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5276
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.