gotta post new rules
I think it is unreasonable to forbid us to use pastebin in a program language group...What should I do if I want show some large code?
Nomid Íkorni-Sciurus
I mean there are almost 16.000 users
Nomid Íkorni-Sciurus
imagine if everybody wrote at once.
Anonymous
I think it is unreasonable to forbid us to use pastebin in a program language group...What should I do if I want show some large code?
Pastebin is not prohibited here. Infact it is encouraged. However, if you are a new user, you are restricted from posting URLs to avoid spam. That restriction would be relaxed if you have posted here for a while.
Michel
This is what I mentioned here https://t.me/programminginc/442373
Oh, sorry, I didn't follow the conversation. Thanks
smene
Hi, I have a problem with cmake
smene
CMakeList.txt: https://nekobin.com/jeposomope Build Traceback: https://nekobin.com/salatigare
Anonymous
Hi guys
Anonymous
A company stores the age and salaries of its employees.Write a program that gives us how many employees who are older than L years get a salaryless than M.Input The frst line of the standard input contains the count of employees (1≤N≤100), theage limit (1≤L≤100) and the salary limit (1≤M≤2000000). The next N lines contain theage (1≤A≤100) and salary (1≤S≤2000000) of an employee each.Output The frst line of the standard output should contain the count of employees who areolder than L and earn more than M. Example Input 6 40 200000 42 150000 33 100000 25 600000 66 80000 25 200000 42 800000 Output 2
Anonymous
I need your help please 😢🙏
Leovan
Who's know why i need to create a second template to make operator<< friendly? template <typename T> class List { template <typename Type> friend std::ostream & operator<<(std::ostream & os, const List <Type> & list); ... }; template <typename T> std::ostream & operator<<(std::ostream & os, const List <T> & list) { if (!list.is_empty()) { Node <T> * tmp = list.head; while (tmp != nullptr) { os << tmp->data << " -> "; tmp = tmp->next; } } return os; }
Anonymous
Anyone use vs codium?
\Device\NUL
Anyone use vs codium?
It just VS Code without proprietary like Chromium does
Anonymous
Thank you
Grigoriy
Hi, I need advice. class TObserver { public: virtual ~TObserver(void) = default; virtual void dataChanged(void) = 0; }; using TObserverSptr = std::shared_ptr<TObserver>; class TObservable { private: std::list<TObserverSptr> m_clObservers; public: void notifyChanged(void) { for (const TObserverSptr& o : m_clObservers) o->dataChanged(); } void subscribe(const TObserverSptr& rObserver) { m_clObservers.push_back(rObserver); } }; // worker class, that implements same work class TWorkerImpl : public TObserver, // I want to maka PROTECTED inheritance protected std::enable_shared_from_this<TWorkerImpl> { protected: // I placed this function in protected section, despite public inheritance. // Is it OK? virtual void dataChanged(void) override {} public: void attach(TObservable* pObservable) { pObservable->subscribe(shared_from_this()); } void doSomeWork(void) { // some work here ......... } }; In this example, I am forced to use public inheritance from TObserver. But I want to use protected one. I don't need to use TWorkerImpl as TObserver anywhere, except in TWorkerImpl::attach. But it is required by std::shared_ptr for implicit conversion TWorkerImpl to TObserver. How can I do without public inheritance? Is it worth to get it?
Anonymous
Hello, i am just learning c programming and i am trying to write a program that increases salary at the same percentage for five months while tax remain the same.
Anonymous
Guys I need some help, please 😭😢
klimi
Guys I need some help, please 😭😢
Don't ask to ask, just ask
Anonymous
Hello, i am just learning c programming and i am trying to write a program that increases salary at the same percentage for five months while tax remain the same.
It is easy. D%- percentage of salary increased ,T- tax Si - initial salary S -salary after number of n months S= (Si+T)*(((100+D)/100)^n)-T
Anonymous
Hi, I need advice. class TObserver { public: virtual ~TObserver(void) = default; virtual void dataChanged(void) = 0; }; using TObserverSptr = std::shared_ptr<TObserver>; class TObservable { private: std::list<TObserverSptr> m_clObservers; public: void notifyChanged(void) { for (const TObserverSptr& o : m_clObservers) o->dataChanged(); } void subscribe(const TObserverSptr& rObserver) { m_clObservers.push_back(rObserver); } }; // worker class, that implements same work class TWorkerImpl : public TObserver, // I want to maka PROTECTED inheritance protected std::enable_shared_from_this<TWorkerImpl> { protected: // I placed this function in protected section, despite public inheritance. // Is it OK? virtual void dataChanged(void) override {} public: void attach(TObservable* pObservable) { pObservable->subscribe(shared_from_this()); } void doSomeWork(void) { // some work here ......... } }; In this example, I am forced to use public inheritance from TObserver. But I want to use protected one. I don't need to use TWorkerImpl as TObserver anywhere, except in TWorkerImpl::attach. But it is required by std::shared_ptr for implicit conversion TWorkerImpl to TObserver. How can I do without public inheritance? Is it worth to get it?
First of all virtual functions and access specifiers don't mix well. You can have a virtual function in the public section in a base class and override it as a private function in the derived class and yet still call this private function through a pointer or reference to the base class. I usually follow Herb Sutter's advice where I make my virtual functions private/protected and normal public methods as non virtual wherever possible. I call the virtual functions from within the public methods. In your case, you can define the dataChanged method in TObserver class as protected. Add another public non virtual function like onDataChange and call the dataChanged function from within it. Now in your TWorkerImpl class, you can use protected inheritance and override the dataChanged method as a protected method and things would work just fine
Grigoriy
First of all virtual functions and access specifiers don't mix well. You can have a virtual function in the public section in a base class and override it as a private function in the derived class and yet still call this private function through a pointer or reference to the base class. I usually follow Herb Sutter's advice where I make my virtual functions private/protected and normal public methods as non virtual wherever possible. I call the virtual functions from within the public methods. In your case, you can define the dataChanged method in TObserver class as protected. Add another public non virtual function like onDataChange and call the dataChanged function from within it. Now in your TWorkerImpl class, you can use protected inheritance and override the dataChanged method as a protected method and things would work just fine
It didn't help. class TObserver { protected: virtual void doDataChanged(void) = 0; public: virtual ~TObserver(void) = default; void dataChanged(void) { doDataChanged(); } }; using TObserverSptr = std::shared_ptr<TObserver>; class TObservable { private: std::list<TObserverSptr> m_clObservers; public: void notifyChanged(void) { for (const TObserverSptr& o : m_clObservers) o->dataChanged(); } void subscribe(const TObserverSptr& rObserver) { m_clObservers.push_back(rObserver); } }; // worker class, that implements same work class TWorkerImpl : protected TObserver, // I want to use PROTECTED inheritance, but I can't protected std::enable_shared_from_this<TWorkerImpl> { protected: // I placed this function in protected section, despite public inheritance. // Is it OK? virtual void doDataChanged(void) override {} public: void attach(TObservable* pObservable) { // !!! error: no viable conversion from 'shared_ptr<TWorkerImpl>' to 'const shared_ptr<TObserver>' pObservable->subscribe(shared_from_this()); // no viable conversion } }; The compiler can't provide implicit conversion from TWorkerImpl to TObserver. In my opinion, it is due to fact that type conversion mast be inside copy constructor of std::shared_ptr<TObserver> which is not friend to TWorkerImpl. I don't know, how to allow such type conversion from within TWorkerImpl::attach. Sorry for my English.
Ali
Find the error in the code and explain why int y, *yptr; *yptr = 10; yptr = &y; y = 5; *yptr = 10; cout << *yptr;
\Device\NUL
i didn't understand
yptr is undefined so it points to random address
\Device\NUL
ok thank you
Please don't pm
\Device\NUL
The compiler should be smart enough to tell you what's the problem
Pavel
The compiler should be smart enough to tell you what's the problem
If it's a modern compiler and warnings are enabled
Ali
where is the error and why? int data; int*const ptr = &data; *ptr = 5; ptr = NULL; int*const ptr2;
Anonymous
It didn't help. class TObserver { protected: virtual void doDataChanged(void) = 0; public: virtual ~TObserver(void) = default; void dataChanged(void) { doDataChanged(); } }; using TObserverSptr = std::shared_ptr<TObserver>; class TObservable { private: std::list<TObserverSptr> m_clObservers; public: void notifyChanged(void) { for (const TObserverSptr& o : m_clObservers) o->dataChanged(); } void subscribe(const TObserverSptr& rObserver) { m_clObservers.push_back(rObserver); } }; // worker class, that implements same work class TWorkerImpl : protected TObserver, // I want to use PROTECTED inheritance, but I can't protected std::enable_shared_from_this<TWorkerImpl> { protected: // I placed this function in protected section, despite public inheritance. // Is it OK? virtual void doDataChanged(void) override {} public: void attach(TObservable* pObservable) { // !!! error: no viable conversion from 'shared_ptr<TWorkerImpl>' to 'const shared_ptr<TObserver>' pObservable->subscribe(shared_from_this()); // no viable conversion } }; The compiler can't provide implicit conversion from TWorkerImpl to TObserver. In my opinion, it is due to fact that type conversion mast be inside copy constructor of std::shared_ptr<TObserver> which is not friend to TWorkerImpl. I don't know, how to allow such type conversion from within TWorkerImpl::attach. Sorry for my English.
Oh I thought from your question the problem was defining a virtual function as protected despite it being public in the base class. I thought you wanted to design it better. The problem here is that you want to convert a shared_ptr to a derived class to shared pointer to a base class. This conversion is possible only when the inheritance is public. There is no other way around this.
klimi
where is the error and why? int data; int*const ptr = &data; *ptr = 5; ptr = NULL; int*const ptr2;
6 int data; 7 int*const ptr = &data; 8 *ptr = 5;  9 ptr = NULL; ■ Cannot assign to variable 'ptr' with const-qualified type 'int *const' 10 int*const ptr2;
Icefrog2000
https://github.com/Perfare/Il2CppDumper
I bet it is an ad acount.
Пожилой Христос
I can use Win32 lib for cross-platform use?
Anele
Hello everyone
Harleen
Hello everyone
Hello 😊
Harleen
c++ I have a a json file and I have to read it using nlohmann. As I read it, I have to also put the keys in the map object that I have created (which in turn have a map object as json can have further keys inside keys). I have used ifstream with nlohmann::json Ifstream MyFilecontent >> nlohmann::json But i don’t know how to go ahead from here. Could anyone please help?
Harleen
Nlohmann is a library for json in c++.
Gilded
i cant read books, i only watch lectures, i use my udemy premium account, its enough right?what more in books?
EYE LORD
Anyone wants to discuss some projects ideas with me
Ali
Find the error in the following code and explain why. int data; const int* ptr; ptr = &data; *ptr = 5;
Gilded
i also want to work with
Gilded
Anyone wants to discuss some projects ideas with me
for which all os devices u code for
Anonymous
printf("The increment is:%f\n", outstanding);         printf("Increment and Tax over the five years\n");         multiplier = 1;         float newtax = 0.25 * (outstanding * grosssalary + grosssalary);         float newpay = grosssalary + (grosssalary * outstanding);         float newnet = newpay - newtax;         float newincrement = outstanding * grosssalary;                 for (multiplier = 1; multiplier <= 5; multiplier = multiplier + 1)         {             printf("year %d: %f",multiplier, newtax);             printf(" %f\n", newnet);         }         
Anonymous
Please how do i make this program increase pay by 25 percent continously for 5 times will tax is deducted as well
Anonymous
I meant while tax ia deducted as well
Anonymous
Here is the question i am trying to solve: if an employee is giving the same salary increment every year for the next 5 months calculate the per montj net pay after tax deduction of 25%
Anonymous
Show the code
printf("The increment is:%f\n", outstanding);         printf("Increment and Tax over the five years\n");         multiplier = 1;         float newtax = 0.25 * (outstanding * grosssalary + grosssalary);         float newpay = grosssalary + (grosssalary * outstanding);         float newnet = newpay - newtax;         float newincrement = outstanding * grosssalary;                 for (multiplier = 1; multiplier <= 5; multiplier = multiplier + 1)         {             printf("year %d: %f",multiplier, newtax);             printf(" %f\n", newnet);         }         
\Device\NUL
I can use Win32 lib for cross-platform use?
You can't, it's closed source. But you can run windows apps on POSIX OS using wine compability layer.
\Device\NUL
Thanks
But native binary is better than run it using compability tool
Пожилой Христос
But native binary is better than run it using compability tool
Thanks, what library can i use without rewriting all the code?
Пожилой Христос
I can throw off the code here for evaluation and criticism, but am I still using SFML?
\Device\NUL
Thanks, what library can i use without rewriting all the code?
I think you can't. I never find someone implementing Windows API to POSIX API. But you can compile POSIX header in Windows with Unix compability layer using Cygwin or MinGW. some of posix header is unistd.h. Unix compatibility layers such as Cygwin and MinGW also provide their own versions of unistd.h. In fact, those systems provide it along with the translation libraries that implement its functions in terms of win32 functions. https://en.wikipedia.org/wiki/Unistd.h
Пожилой Христос
I just started writing this, but I want to hear your opinion and criticism #include <SFML/Graphics.hpp> #include <iostream> using namespace std; using namespace sf; #define NumberButton 9 RenderWindow window(VideoMode(800, 600), "Encryption", Style::Close); struct MyChoice { string MyChoice; }; int main() { MyChoice MyChoice; Texture background; Sprite BACKGROUND; background.loadFromFile("texture/background.jpg"); BACKGROUND.setTexture(background); BACKGROUND.setScale( window.getSize().x / BACKGROUND.getGlobalBounds().width, window.getSize().y / BACKGROUND.getGlobalBounds().height); Image icon; if (!icon.loadFromFile("texture/icon.png")) return EXIT_FAILURE; window.setIcon(icon.getSize().x, icon.getSize().y, icon.getPixelsPtr()); window.setVerticalSyncEnabled(true); string* TEXT = new string[NumberButton]{ "Encryption:", "Decoding:", "Caesar cipher", "Vernam cipher", "Hill cipher", "Vigenère cipher", "Gronsfeld cipher", "Rivest–Shamir–Adleman" }; Text text[NumberButton]; Font font; if (!font.loadFromFile("font/AnonymousPro-Bold.ttf")) return EXIT_FAILURE; for (size_t i = 0; i < NumberButton; i++) //set textures and sprites { if (i < NumberButton - 1) text[i].setString(TEXT[i]); text[i].setFont(font); text[i].setCharacterSize(24); text[i].setFillColor(Color::Red); if (i > 1 || i < NumberButton - 1) text[i].setPosition(500, 75 + ((i - 2) * 50)); } text[0].setPosition(120,75); //Encryption text[1].setPosition(120,300); //Decoding MyChoice.MyChoice = "Cipher: " + TEXT[2]; text[NumberButton - 1].setString(MyChoice.MyChoice); text[NumberButton - 1].setPosition(10, 10); delete[]TEXT; TEXT = nullptr; while (window.isOpen()) //drow sprite { Event event; while (window.pollEvent(event)) { if (event.type == Event::Closed) window.close(); } window.clear(); window.draw(BACKGROUND); for (size_t i = 0; i < NumberButton; i++) { window.draw(text[i]); } window.display(); } }
Harleen
Hello, Can someone help me iterate over a nested json object and mapping each key to a map using nlohmann’s library?
😊
Any one here those very good knowledge c
😊
Solved any problem
Pavel
Hello, Can someone help me iterate over a nested json object and mapping each key to a map using nlohmann’s library?
By "nested json" you mean nested json object or json written as a string to a json field?
Pavel
Hello, Can someone help me iterate over a nested json object and mapping each key to a map using nlohmann’s library?
If nested json object, you can do get("name") on it, and just iterate over the result using renged for loop Here are some examples: https://json.nlohmann.me/features/iterators/#access-object-key-during-iteration
Пожилой Христос
this is the window for my text encryption program
Artur
Thanks
Why not use latest c++ 20 standard and where you need to go cross platform either use 3rd party libraries like Gtkmm for gui ?
Anonymous
oof
Anonymous
Пожилой Христос
Anonymous
tho probably not the WIn32 API explicitly but most all of .NET except the windows Win32 API (eg HANDLE, PVOID, etc are all part of Win32 API) are portable
Artur
have to rewrite a lot of code
Well if it’s for your own it’s would be a really good development project
Anonymous
Which training should I do to be able to programming a DPI for 100gbps