Home

On Aug 21, 1:50 am, Tristan Wibberley <maihem-...@maihem.org> wrote:
> On Mon, 2007-08-20 at 03:02 -0700, Dhoom@Rock wrote:
> > hello friends finally i found the fault and nw application run fine
> > without any error....thanks every one for helps
>
> > Now new issue is that my application now can assign only integer type
> > data ...
> > like a["dharmesh"]=10 <--
>
> > now i want to assign it either integer or char
> > like a["dharmesh'] = 'D' <--
>
> > it means i should have two function overloading declaration.. like
> > int & operator [] (char * st)
> > char & operator [] (char * st)
>
> > but my application wan't allow me to do so .. WHY ???
>
> You need to do something like this:
>
> template<typename T, typename ID>
> class smart_assignment {
> T* that_;
> ID id;
> public:
> explicit smart_assignment (T* that_, const ID& id_)
> : that(that_), id(id_) {}
>
> template<typename U>
> T& operator= (const U& v) { that->assign(id, v); return *T; }
>
> };
>
> class foo {
> public:
> smart_assignment<foo> operator[] (char*st) {
> return smart_assignment<foo, char*>(this, st);
> }
>
> void assign(char* st, int i) { ... }
> void assign(char* st, char c) { ... }
>
> };
>
> --
> Tristan Wibberley
>
> Any opinion expressed is mine (or else I'm playing devils advocate for
> the sake of a good argument). My employer had nothing to do with this
> communication.- Hide quoted text -
>
> - Show quoted text -



This is your code with some modification as per errors that i get now
this code get run.. i also included some statement but dosent include
here bcz it may confuse u or some one...

Just tell me this when i do like
a["dh"] = 10
then in short function calling is like ==> operator [] --> operator =
--> assign()

now when i want to fetch data from a["dh"] then i will write cout <<
a["dh"] ;
so can u plz tell me what should my changes to fetch data
sucessfully ...

should i have to make function like get() similar to assign()... if
yes then when and how i call it ???

I try but find cunfuse me ...


Template<typename T, typename ID>
class smart_assignment {
T* that;
ID id;
public:
explicit smart_assignment (T* that_, ID& id_)
: that(that_), id(id_) {}


template<typename U>
T& operator = ( U& v) { that->assign(id, v); return *that; }



};


class foo {

public:
smart_assignment<foo,char * > operator[] (char*st) {

return smart_assignment<foo, char *>(this, st);
}

void assign(char* st, int f) { }

void assign(char* st, char c) { }

};

previous
next

about __str__
Re: /dev/null as a file-like object, or logging to nothing
looking for the fastest complex number arithmetics...
Re: Wing IDE for Python v. 3.0 beta1 released
Re: how to get command output using python
instant loans
pozycjonowanie
gustowne meble katowice
internet
samochody carone