Portál AbcLinuxu, 30. října 2025 22:27
 22.10.2023 02:07
🇹🇬             | skóre: 37
             | blog: Grétin blogísek
             | 🇮🇱==❤️ ,   🇵🇸==💩 ,  🇪🇺==☭
        22.10.2023 02:07
🇹🇬             | skóre: 37
             | blog: Grétin blogísek
             | 🇮🇱==❤️ ,   🇵🇸==💩 ,  🇪🇺==☭
        si nedal celej příklad takže nevíme co tam čaruješ, předpokladam že to máš asi jako takle nějak:
#include <string>
class test_class_text
{
private:
    std::string _switch_pin;
public:
    test_class_text(const std::string& switch_pin) :
        _switch_pin(switch_pin)
    {
 
    }
};
class test_class_int
{
private:
    int _switch_pin;
public:
    test_class_int(const int& switch_pin) :
        _switch_pin(switch_pin)
    {
 
    }
};
int main()
{
auto obj = test_class_int({ .switch_pin = 5 }); 
auto obj2 = test_class_text({ .switch_pin = "Lorem ipsum..." });
return 0;
}
noa se mi jako zdá že tam neni problém s tou třídou co dělá s intem ale s tou co dělá se stringem, páč v konstruktoru 'test_class_text' vidim že chce referenci/vodkaz na string zatimco ty tam zkoušíš narvat const char * "Lorem ipsum" :D ;D
když si to jakoby zkusíme zkompilovat uděláním 'g++ -std=c++20 main.cpp' tak nám to asi jako zanadává
main.cpp: In function ‘int main()’:
main.cpp:30:64: error: call of overloaded ‘test_class_text(<brace-enclosed initializer list>)’ is ambiguous
   30 | auto obj2 = test_class_text({ .switch_pin = "Lorem ipsum..." });
      |                                                                ^
main.cpp:7:5: note: candidate: ‘test_class_text::test_class_text(const string&)’
    7 |     test_class_text(const std::string& switch_pin) :
      |     ^~~~~~~~~~~~~~~
main.cpp:2:7: note: candidate: ‘test_class_text::test_class_text(const test_class_text&)’
    2 | class test_class_text
      |       ^~~~~~~~~~~~~~~
main.cpp:2:7: note: candidate: ‘test_class_text::test_class_text(test_class_text&&)’
..a zanadávalo :D :D Vyřešit to mužem třeba tim že dotoho budem strkat dočasnej voběkt std::string
auto obj2 = test_class_text({ .switch_pin = std::string("Lorem ipsum...") });
takle to funguje ale netvrdim že to je nejvíc nejlepší řešení ňáký :D ;D pokud by v konstruktoru třidy 'test_class_text' nebyla ta reference tak by si to samo zavolalo konstruktor std::stringu ale takle tomu asi jako musime pomoct a vysvětlit cože po tom jakože chcem :O ;D
btw si pleteš blog s poradnou a eště si to tady zaspamoval :O :D :D ;D
 22.10.2023 03:58
Jendа             | skóre: 78
             | blog: Jenda
             | JO70FB
        22.10.2023 03:58
Jendа             | skóre: 78
             | blog: Jenda
             | JO70FB
        test_class_int(const int switch_pin) : _switch_pin(switch_pin) {} ?
             22.10.2023 20:19
🇹🇬             | skóre: 37
             | blog: Grétin blogísek
             | 🇮🇱==❤️ ,   🇵🇸==💩 ,  🇪🇺==☭
        22.10.2023 20:19
🇹🇬             | skóre: 37
             | blog: Grétin blogísek
             | 🇮🇱==❤️ ,   🇵🇸==💩 ,  🇪🇺==☭
        u čiselnejch proměnejch ten benefit předáváním referencí taky nebude ňák moc velkej, spiš zanedbatelnej :D ;D
btw von to pak v tom konstruktoru stejně předává hodnotou (páč ty třídy si v proměný '_switch_pin' nedržej referenci ale sou to už normální proměný) nóó takže stačí by nám ta reference co se dotoho jakoby strká vydržela žít jenom po dobu volaní konstruktoru :O ;D
 26.10.2023 09:50
skunkOS             | skóre: 27
             | blog: Tak nějak
        26.10.2023 09:50
skunkOS             | skóre: 27
             | blog: Tak nějak
            
         23.10.2023 00:52
🇹🇬             | skóre: 37
             | blog: Grétin blogísek
             | 🇮🇱==❤️ ,   🇵🇸==💩 ,  🇪🇺==☭
        23.10.2023 00:52
🇹🇬             | skóre: 37
             | blog: Grétin blogísek
             | 🇮🇱==❤️ ,   🇵🇸==💩 ,  🇪🇺==☭
        nj akorátže až nato že mě se ten jeho kod (mirně dopras.. upravenej ale to dělaní s intem je jakoby uplně netknutý) podařilo zkompilovat a pustit :O :D
#include <string>
#include <iostream>
class test_class_text
{
public:
    std::string _switch_pin;
public:
    test_class_text(const std::string& switch_pin) :
        _switch_pin(switch_pin)
    {
 
    }
};
class test_class_int
{
public:
    int _switch_pin;
public:
    test_class_int(const int& switch_pin) :
        _switch_pin(switch_pin)
    {
 
    }
};
int main()
{
auto obj = test_class_int({ .switch_pin = 5 }); 
auto obj2 = test_class_text({ .switch_pin = std::string("Lorem ipsum...") });
std::cout<<"co ma prvni vobekt: "<<obj._switch_pin<<std::endl;
std::cout<<"co ma druhej vobekt: "<<obj2._switch_pin<<std::endl;
return 0;
}
co ma prvni vobekt: 5 co ma druhej vobekt: Lorem ipsum...
test_class_int obj2 = { .switch_pin = 5 }; ? To by ale ta třída musela být POD...
             25.10.2023 02:52
🇹🇬             | skóre: 37
             | blog: Grétin blogísek
             | 🇮🇱==❤️ ,   🇵🇸==💩 ,  🇪🇺==☭
        25.10.2023 02:52
🇹🇬             | skóre: 37
             | blog: Grétin blogísek
             | 🇮🇱==❤️ ,   🇵🇸==💩 ,  🇪🇺==☭
        mi to mý upravený jelo v gcc 10 s argumentem -std=c++20 ale netvrdim žeto je takle jakože dobře :O :O
        Tiskni
            
                Sdílej:
                 
                 
                 
                 
                 
                 
            
    
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.