Jump to content

Recommended Posts

Posted

Boas,

eu tenho uma Generalização onde tem uma class principal e duas sub class's.

eu queria por uma variável na class principal e que tivesse aceso nas suas sub class's.

mas a variável que pretendo adicionar não pode ser nenhum atributo nem método da class principal.

alguém me pode sugerir uma solução?

Posted

e' um pouco dificil perceber o que queres realmente...

[irony]

Podes ter 2 solucoes:

-Usas o boost, decerteza que tem alguma funcao para isso.

-Usas COM, as COM sao muito porreiras 🙂

[/irony]

Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender.

A beleza de um código está em decompor problemas complexos em pequenos blocos simples.

"learn how to do it manually first, then use the wizzy tool to save time."

"Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."

Posted
#include <iostream>

class Mae {
   protected: // É isto que queres?
       int variavel;
};

class Filha : Mae {
   public:
       void setVariavel(int v);
       void printVariavel();
};

void Filha::setVariavel(int v) { variavel = v; }
void Filha::printVariavel() { printf("%d\n", variavel); }

using namespace std;
int main(int argc, char *argv[]) {
   Filha f;

   f.setVariavel(5);
   f.printVariavel();

   return 0;
}

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.