Whiteangel Posted September 23, 2013 at 05:37 PM Report #525594 Posted September 23, 2013 at 05:37 PM (edited) Class tanque2 Private comprimento As Single Private largura As Single Private altura As Single Public Function volume() As Single Return comprimento * largura * altura End Function End Class Dim T1 As New tanque2 t1.comprimento = 5 t1.largura = 4 t1.altura = 3 MsgBox(t1.volume) Escreva uma nova versão da classe tanque2, que prmita as instruções funcionar sem problema. Nota: "A solução deve passar pela criação de propriedades públicas para acesso aos dados privados da classe e não pela simples conversão das variáveis privadas para publicas" Eu estou a fazer assim mas dá me erro. Alguém me poderia ajudar?? Public Class tanque2 Private comprimento As Single Private largura As Single Private altura As Single Public Function volume() As Single Return comprimento * largura * altura End Function Public Property comprimento2() As String Get 'devolve o campo nome Return comprimento End Get Set(ByVal value As String) 'atribui comprimento = value End Set End Property End Class Edited September 23, 2013 at 07:13 PM by thoga31 Tags code + GeSHi
bioshock Posted September 23, 2013 at 06:53 PM Report #525604 Posted September 23, 2013 at 06:53 PM Qual é o erro? Assim de gás talvez seja os tipos de dados. Estás atribuir um campo String a um campo Single.
Whiteangel Posted September 23, 2013 at 08:12 PM Author Report #525608 Posted September 23, 2013 at 08:12 PM Qual é o erro? Assim de gás talvez seja os tipos de dados. Estás atribuir um campo String a um campo Single. Error 2 'WindowsApplication1.tanque2.largura' is not accessible in this context because it is 'Private'.
nelsonr Posted September 23, 2013 at 08:29 PM Report #525610 Posted September 23, 2013 at 08:29 PM Se queres aceder dessa forma, muda a definição das variaveis de private para public
Whiteangel Posted September 23, 2013 at 09:27 PM Author Report #525613 Posted September 23, 2013 at 09:27 PM Se queres aceder dessa forma, muda a definição das variaveis de private para public Se queres aceder dessa forma, muda a definição das variaveis de private para public Mas so que nao poço ir por esta forma : Nota: "A solução deve passar pela criação de propriedades públicas para acesso aos dados privados da classe e não pela simples conversão das variáveis privadas para publicas"
nelsonr Posted September 23, 2013 at 09:36 PM Report #525616 Posted September 23, 2013 at 09:36 PM É o que dá ler os posts na diagonal 😄 Deve ser algo assim: Class tanque2 Private _comprimento As Single Private _largura As Single Private _altura As Single Public Property comprimento() As Single Get Return _comprimento End Get Set(ByVal value As Single) _comprimento = value End Set End Property Public Property largura() As Single Get Return _largura End Get Set(ByVal value As Single) _largura = value End Set End Property Public Property altura() As Single Get Return _altura End Get Set(ByVal value As Single) _altura = value End Set End Property Public Function volume() As Single Return _comprimento * _largura * _altura End Function End Class
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now