Link to home
Start Free TrialLog in
Avatar of mahmad
mahmad

asked on

C++ Templates

see this code:
class string{
public:
      str[20];
      int a;
      int b;
}

///////////////////////////////

template <type,key>
class word
{
private:
      type data;          
      int q;
      int p;
public:
      whatever you want
}

///////////////////////////////////

template <class type,class key>
class nod
{
private:
      word<type,key> tp;
public:

      add(word<type,key>&);

      
      whatever you want
}

template ......... add(word<type,key>& w)
{
/*      
here how do you tell the compiler that you want to access certain
element in the 'type' that I will instantiate as 'key'

eg.: I will do      in main()  nod<string,int>
Is there no way to tell the compiler that
I what I want to do is nod <string, word::a> I hope you understand
what I mean although the syntax may be incorrect.

Secondly suppose I want to access word::b
so how do I do
can I do(probably can't)   int i=w.data::key;
i.e get the element said as key in the data type in the word class.

*/
}
Avatar of obg
obg

There is a C++ area...
ASKER CERTIFIED SOLUTION
Avatar of murrayc
murrayc

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial