boost::array call by reference...



  • leider werd ich da nun 2 iteratoren brauchen?
    damit ich dann in den arrays eines arrays weiter gehen kann?

    cu



  • volkard schrieb:

    man nimmt lieber != statt <, denn != klappt effizient bei den verrücktesten iteratoren, während < bei manchen iteratoren lahm ist. willst ja nicht immer nachdenken müssen, ob jetzt != oder < gut ist.

    Vor allem muss es dann nicht zwangsläufig ein Random Access Iterator sein.



  • boost4x4::const_iterator pos;
    
    for (pos=array->begin(); pos<array->end(); ++pos) {
    	std::cout << (*pos)[0] <<' ' << (*pos)[1] <<' ' << (*pos)[2] <<' ' << (*pos)[3] << std::endl; 
        }
    

    ich hab das etwas kompliziert...wie kann ich da mit einen 2ten interator auf die arrays eines array zugreifen?

    cu



  • for (pos = array->begin(); pos != array->end(); ++pos) {
    

    cu



  • typedef boost4x4::const_iterator It; 
    
    for (It pos1=array->begin(); pos1!=array->end(); ++pos1) 
      for (It pos2=pos1->begin(); pos2 != pos1->end(); ++pos2) { 
        std::cout << (*pos) <<' '; 
      }
    std::cout << std::endl;
    

    So zum Beispiel?



  • Sorry, hab mich vertan.

    typedef boost4x4::const_iterator It1; 
    typedef boost::array<std::string,4>::const_iterator It2;
    
    for (It1 pos1=array->begin(); pos1!=array->end(); ++pos1) 
      for (It2 pos2=pos1->begin(); pos2 != pos1->end(); ++pos2) { 
        std::cout << (*pos2) <<' '; 
      }
    std::cout << std::endl;
    


  • boost4x4 *DoSomething(boost4x4* array)
    {
    	if((*array)[0][0] == "spring")
    		return (&array)[0];
    
    	return (&array)[3];
    }
    

    aufruf:

    std::cout << &DoSomething(&seasons_i18n)[0] << std::endl;
    

    nun will ich einen pointer auf das erste array zurückgeben...
    wenn ich nun so wie oben die funktion aufrufe, warum wird dann eine adresse ausgegeben? will nun das erste element ausgeben auf das array der pointer zeigt...

    cu



  • return &(*array)[3];
    

    Und &DoSomething ist auch nicht richtig, du meintest wohl eher

    std::cout << (*DoSomething(&seasons_i18n))[0] << std::endl;
    


  • hm...klappt leider auch nicht!!

    bei: return &(*array)[0];
    c:\Informatik\Temp3\main.cpp(102) : error C2440: 'return' : cannot convert from 'boost::array<T,N> *__w64 ' to 'boost4x4 *'
            with
            [
                T=std::string,
                N=4
            ]
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    
    bei: bei: return &(*array)[3];
    c:\Informatik\Temp3\main.cpp(104) : error C2440: 'return' : cannot convert from 'boost::array<T,N> *__w64 ' to 'boost4x4 *'
            with
            [
                T=std::string,
                N=4
            ]
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    
    bei: std::cout << (*DoSomething(&seasons_i18n))[0] << std::endl;
    c:\Informatik\Temp3\main.cpp(137) : error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'boost::array<T,N>' (or there is no acceptable conversion)
            with
            [
                T=std::string,
                N=4
            ]
    


  • (sachen, die ich nicht mag, hab ich gelöscht)
    volkard


Anmelden zum Antworten