Re: This I simply can't swallow
From: Clark S. Cox III (clarkcox3_at_gmail.com)
Date: 02/16/05
- Next message: Thomas Matthews: "Re: 32-bit adder in c/c++"
- Previous message: Chris \( Val \): "Re: Answer needed"
- In reply to: Morten Gulbrandsen: "This I simply can't swallow"
- Next in thread: Gary Labowitz: "Re: This I simply can't swallow"
- Reply: Gary Labowitz: "Re: This I simply can't swallow"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 16 Feb 2005 09:30:58 -0500
On 2005-02-16 07:33:05 -0500, Morten Gulbrandsen
<Morten.Gulbrandsen@rwth-Aachen.DE> said:
> Hello programmers,
>
> according to this link :
>
>
> URL:
>
> http://www.deakin.edu.au/~agoodman/ctutorial/818.html
>
>
> An encapsulated object is often called an abstract data type.
>
> Is this true ?
No, encapsulation and abstract data types are completely orthogonal
concepts. Encapsulation is hiding the data/implementation of a class
behind a public interface. For instance, take the std::vector class.
There are any number of ways that it could be implemented "under the
hood", but as long as it presents the correct public interface, code
using it will continue to function properly.
> The code actually runs well, with some modifications,
> I also like the explanations,
>
> Except this:
> Class
> A grouping of data and methods (functions). // accepted
> A class is similar to a type in ANSI-C. // warning
I see nothing wrong with this. 'int' is an ANSI-C type:
int i; //A variable of type int
int *p; //A pointer to int
int f(); //A function returning int
sizeof(int); //The number of bytes needed to store an int
class MyClass {};
MyClass i; //An instance of MyClass
MyClass *p; //A pointer to MyClass
MyClass f(); //A function returning MyClass
sizeof(MyClass); //The number of bytes needed to store an MyClass
Seems pretty similar to me.
> Object
> An instance of a class, // accepted
> similar to a variable defined as an instance of a type. // warning
Again, I see nothing wrong with this.
int i; //variable defined as int
MyClass c; //variable defined as an instance of MyClass
Again, seems pretty similar to me.
> This I simply can't swallow.
>
> I believe a class in C++ is like a struct,
> or typedef struct in ANSI C.
classes and structs are the same thing in C++. The only difference is
that structs default to "public" for its members and inheritence.
> And any struct can also contain function pointers.
Anything a struct can do, a class can do too, as they are the same thing.
>
> A type is a data type like int i=1;
No, in what you've typed there, "int" is a type
> Please correct me.
>
> What exactly is the difference between
> encapsulation and an ADT?
An ADT is a type that cannot, itself, be instantiated. ADTs are useful
for, among other things, providing a base used to build other classes
while providing a common interface.
> In C++?
In C++, to make a class an ADT, you simply need to make one or more of
its member functions pure virtual.
class MyClass
{
public:
virtual void Foo() = 0;
};
In the above, Foo is a pure virtual function. This makes it impossible
to construct instances of MyClass.
>
> best regards
>
> Morten Gulbrandsen
-- Clark S. Cox, III clarkcox3@gmail.com
- Next message: Thomas Matthews: "Re: 32-bit adder in c/c++"
- Previous message: Chris \( Val \): "Re: Answer needed"
- In reply to: Morten Gulbrandsen: "This I simply can't swallow"
- Next in thread: Gary Labowitz: "Re: This I simply can't swallow"
- Reply: Gary Labowitz: "Re: This I simply can't swallow"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|