Abstact types

Started by
0 comments, last by braves 23 years, 9 months ago
I have a simple questions if anyone can help. Here they are: 1) Can someone explain what a abstract data types are and what abstact base class are. If there is such a thing, what is a abstract function? What is the difference between a abstract class and a normal class which I think is called a concrete class? 2) Why is it you can''t do void function(int a[][9]) {} main() { int a[10][9]; function(a); } you have to do it like this void function(int a[][9]) {} main() { int a[10][9]; function(a); } but you can do this void function(int *) {} main() { int a[10]; function(a); } 3)What''s the difference between private and protected data types? Thank you all for your help in advance. Braves
Advertisement

I''m not sure I see the difference between the first two program-fragments you have given...

As far as abstract classes and functions go, it all has to do with object oriented programming, inheritance, and polymorphism. (Who ever broght that word into use should be shot).

I''m not great at explaining things, but here is an example:

class Reader {
public:
virtual char readChar() = 0; // abstract definition
};

class MemReader : public Reader {
public:
char readChar() { return *(ptr++); }
}

class FileReader : public Reader {
public:
char readChar() { return getc(fileStream); }
}


Here, Reader is an abstract class because it contains an abstract function. What this basically says is that any class derived from Reader MUST implement a version of readChar. Also, because Reader contains an abstract function, it can not be instantiated, because it wouldn''t know what to do if readChar was called. The ''virtual'' modifier in Reader simply says that it is possible for classes derived from Reader to effectively override any functionality that may or may not have been given in the original declaration.

A quick run-down of access modifiers: (And I mean quick)...

''public'' means that the field/function can be accessed from anywhere that the object can.
''protected'' means that only functions declared as either part of the class or any class derived from the original class have access.
''private'' means that only functions declared in that object have access rights.

Hope that helped. I know it confused the hell out of me...

This topic is closed to new replies.

Advertisement