Software Archive
Read-only legacy content
17061 Discussions

public/private question

rahzan
Novice
303 Views
I learned all oop in java whereby I have lot of occasion to be confused by similarly named constructs in cvf.

According to the docs I should be able to declare separte items within a type as public or private but no permutation of these keywords seems to satisfy the compiler. (In this case I am trying to write a class like that of Vectors of Java.) I do not want the user to have direct access to the properties or scratch pads.
 
	type Real4AutoArray  
		public,real(4),allocatable:: val(:)   
		private,real(4),allocatable:: vcopy(:)  
		private,integer,private:: currSize,incrSize  
	end type Real4AutoArray  
  
...methods like getcurrSize  

Is there a way to declare these public and private attributes?

Thanks, Tim
0 Kudos
3 Replies
Steven_L_Intel1
Employee
303 Views
Not quite like that. Fortran doesn't allow you to make some components public and some private. It's all or nothing - to make all the components private, put the PRIVATE keyword all by itself following the TYPE statement. You can't even have a type containing some public components and then a component of a private derived type - the standard requires in such cases that the outer type be privaye as well.

The way you'd probably have to do this is with functions in the module to set and get the VAL field.

Steve
0 Kudos
rahzan
Novice
303 Views
Thanks,
I'm not sure if I understand your second statement. but before I ask about that I wonder:
1. what is the use of an (all private) derived type if none of its components are available??
2. Did you mean something like this is not possible either?
type X
private
real A
end type X
type Y
type (X) YA
real YB
end type Y

so while YA is technically public its real content in A is not.

But you say does not work either.

note on the side: Too bad the help files do not have URLs so we can direct each other to the a page which clear or cause a given bit of confusion such as this

Tim
0 Kudos
Steven_L_Intel1
Employee
303 Views
A private type allows the user to declare objects of that type, but they must pass them as arguments to module routines to use them.

The manuals are in HTML form at http://www.compaq.com/fortran/docs and you can link to indivdual pages if you like - for example here.

Steve
0 Kudos
Reply