Page 1 of 1
Help ( C++ )
Posted: 26 Nov 2008 18:10
by 43_Scuba
S!
Alguem sabe o que e isso ...
SimpleCat::SimpleCat ()
{
itsAge = new int (2);
itsWeight = new int (5);
}
SP!
Posted: 26 Nov 2008 23:12
by 22_Ponte
S!
Scuba.
Parece ser uma função que retorna ou define duas variáveis do tipo Integer.
ItsAge e ItsWeight
SP!
Posted: 26 Nov 2008 23:56
by 43_Scuba
S!
O Ponte, eu sei.
O que eu nao sei é
itsAge = new int (2);
O resto eu seu
#pragma hdrstop
#include <iostream.h>
//---------------------------------------------------------------------------
#pragma argsused
class SimpleCat
{
public:
SimpleCat ();
~SimpleCat ();
int GetAge () const {return *itsAge;}
void SetAge (int age) {*itsAge = age;}
int GetWeight () const {return *itsWeight;}
void setWeight (int weight) {*itsWeight = weight;}
private:
int *itsAge;
int *itsWeight;
};
SimpleCat::SimpleCat ()
{
itsAge = new int (2);
itsWeight = new int (5);
}
SimpleCat::~SimpleCat ()
{
delete itsAge;
delete itsWeight;
}
int main(int argc, char* argv[])
{
SimpleCat *Frisky = new SimpleCat;
cout << "Frisky is " << Frisky->GetAge() << " years old\n";
Frisky->SetAge(5) ;
cout << "Frisky is " << Frisky->GetAge() << " years old\n";
delete Frisky;
system("pause");
return 0;
}
Na verdade, o que eu nao estendo é
int (2)
int s;
int s = 1;
mais
int (2); (eu nao entendi)
SP!
Posted: 27 Nov 2008 07:55
by 22_Ponte
S!
Não seria o Int(2) a definição de uma variável numérica com duas posições?
Eu acho que sim.
Em outras linguagem é assim que se define.
variavelInteira2Posicoes = new Int(2)
variavelTexto20Posicoes = new Char(20)
Espero que ajude.
SP!
Posted: 27 Nov 2008 11:08
by 43_Scuba
S!
Ponte, acho que você ta certo
22_Ponte wrote:
variavelInteira2Posicoes = new Int(2)
variavelTexto20Posicoes = new Char(20)
Obrigato pela ajuda
SP!
Posted: 27 Nov 2008 17:45
by 03_Vingador
S!
Só não entendi uma coisinha?
Tudo
O que significa isso?
SP!
Posted: 27 Nov 2008 19:54
by 43_Scuba
S!
Vinga, não tenta endender, por que eu tambem não
brincadeira
SP!