Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Scope for abstract data types?

    Hey there, i'm relativly new to programming in general so my apologies if this is trivial.. I did try to find an answer via searching, but i didn't happen across anything satisfactory.

    I'm currently implementing a structure of abstract data types with the idea of them being linked to eachother via arrays. The problem i'm having is that while i can manipulate a data type in the method it was created, it's not recognized in another method. eg :

    Code:
    class Yarr{
    
         public void Yarr(){
    
         Abstract a1 = new Abstract();
    
         yarr2();
    
         }
    
         public void yarr2(){
    
         a1.useSomeMethod();
    
         }
    }
    Will result in the compiler telling me that the symbol a1 cannot be seen. The data type class file is declared as public, as is the method i'm trying to access within it.. So i'd assume it'd be visible no matter where you try to look at an instance from. Like i say i'm a little new, so i may be missing something trivial here.

    Thanks in advance for any help.

    -Marcus

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Location
    Willow Grove, PA
    Posts
    169
    Thanks
    1
    Thanked 27 Times in 27 Posts
    Code:
    class Yarr {
    
    	private Abstract a1;
    
    	public void Yarr(){
    		this.a1 = new Abstract();
    		yarr2();
    	}
    
    	public void yarr2(){
    		this.a1.useSomeMethod();
    	}
    }

  • #3
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thankyou, i understand why that works.

    -Marcuss


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •