Anonymous
why is output changing
Anonymous
Liam
Please kindly check the pinned message in this group for the section "Questions".
Olusola
/help
Group Butler
Start me to get the list of commands
Anonymous
@roxifas bro ! Can u help me in this
Liam
Why do we need to declare a constructor explicit?
There is a mechanism called implicit conversion in C and C++. When you call an expression that requires the type T1, however you give it a variable typed in T2, implicit conversion happens. In C++, a user defined class might contains many constructors. For those who has only one parameter, a new implicit conversion from the type of the parameter to the user defined class is registered. For example, if you have the following definition of class Foo, the conversion from int to Foo is registered: class Foo { public: Foo(int x) : x_(x) {} private: int x_ = 0; // other data members }; This time, everytime an object of type Foo (or related const lvalue reference or rvalue reference type) is required, passing a variable typed in int will trigger an implicit conversion, and construct a temporary object of type Foo. #include <iostream> class Foo { public: Foo(int x) : x_(x) {} private: int x_ = 0; }; void bar(Foo&& foo) { std::cout << "function[void bar(const Foo& foo)] called.\n"; } int main() { bar(42); return 0; } In some cases, this kind of implicit conversion helps you; however, in other cases, it ruins your code and becomes a hard-to-debug defect. Whether it helps or not depends on the semantic of the expression that triggers the implicit conversion, which is impossible for the compile to detect. #include <iostream> #include <string> struct Foo { Foo() = default; Foo(int x) : x_(x) {} int compare(const Foo& other) { // designed to compare the length_ of two Foo objects if (this->length_ < other.length_) { return -1; } else if (other.length_ < this->length_) { return 1; } else { return 0; } } int x_ = 0; int length_ = 0; }; int main() { Foo bar; bar.length_ = 100; std::cout << bar.compare(50) << std::endl; // happens the implicit conversion return 0; } In the above code, the one-parameter constructor of the class Foo takes an int variable and thus defines the conversion. Hence, when calling bar.compare(50), this conversion is triggered implicitly. However, in the constructor, the length_ of the temporary remains 0, which is not what we desired. Of course, we want to compare the length_ of two well constructed Foo objects. The origin of the problem roots in the implicitly triggered conversion. To solve the problem, the explicit keyword is used for prohibitting impilicit conversion (and explicit conversion is still allowed).
Roxifλsz 🇱🇹
@roxifas bro ! Can u help me in this
Your while loop is checking whether the end of file was reached, the file read operation is at the end of the loop. After the last line was read, it tries to read again and that sets the end of file bit which prevents the loop from firing one more time
Roxifλsz 🇱🇹
In your first code the loop just worked one more time, but when it tried to read a line, it was already the end, so it doesn't read anything. And the same name gets written again
Roxifλsz 🇱🇹
I'm not sure if I explained that well, hope you understand
Raj
/help@GroupButler_bot
Group Butler
Start me to get the list of commands
Anonymous
/help@GroupButler_bot
Group Butler
Start me to get the list of commands
Anonymous
what king of software you all us
Anonymous
use
Anonymous
i'm using netbeans
Anonymous
who is using notepad++
Anonymous
send to me lnk of notepad++ donwload
Anonymous
send to me lnk of notepad++ donwload
https://notepad-plus-plus.org/download/v7.5.4.html
Anonymous
thanks bro
Anonymous
may god bless you
Anonymous
how about xzampp? do you have it
r35
GM all... who's from gh or ng here?
r35
pls i need link to c++ video tutorials...pdfs make me sleep xd
Anonymous
pls i need link to c++ video tutorials...pdfs make me sleep xd
theres plenty out there, just search "C++ tutorial" on youtube or something like that
Anonymous
Anonymous
Netbeans is win
Anonymous
😂
Anonymous
There is a mechanism called implicit conversion in C and C++. When you call an expression that requires the type T1, however you give it a variable typed in T2, implicit conversion happens. In C++, a user defined class might contains many constructors. For those who has only one parameter, a new implicit conversion from the type of the parameter to the user defined class is registered. For example, if you have the following definition of class Foo, the conversion from int to Foo is registered: class Foo { public: Foo(int x) : x_(x) {} private: int x_ = 0; // other data members }; This time, everytime an object of type Foo (or related const lvalue reference or rvalue reference type) is required, passing a variable typed in int will trigger an implicit conversion, and construct a temporary object of type Foo. #include <iostream> class Foo { public: Foo(int x) : x_(x) {} private: int x_ = 0; }; void bar(Foo&& foo) { std::cout << "function[void bar(const Foo& foo)] called.\n"; } int main() { bar(42); return 0; } In some cases, this kind of implicit conversion helps you; however, in other cases, it ruins your code and becomes a hard-to-debug defect. Whether it helps or not depends on the semantic of the expression that triggers the implicit conversion, which is impossible for the compile to detect. #include <iostream> #include <string> struct Foo { Foo() = default; Foo(int x) : x_(x) {} int compare(const Foo& other) { // designed to compare the length_ of two Foo objects if (this->length_ < other.length_) { return -1; } else if (other.length_ < this->length_) { return 1; } else { return 0; } } int x_ = 0; int length_ = 0; }; int main() { Foo bar; bar.length_ = 100; std::cout << bar.compare(50) << std::endl; // happens the implicit conversion return 0; } In the above code, the one-parameter constructor of the class Foo takes an int variable and thus defines the conversion. Hence, when calling bar.compare(50), this conversion is triggered implicitly. However, in the constructor, the length_ of the temporary remains 0, which is not what we desired. Of course, we want to compare the length_ of two well constructed Foo objects. The origin of the problem roots in the implicitly triggered conversion. To solve the problem, the explicit keyword is used for prohibitting impilicit conversion (and explicit conversion is still allowed).
Thanks
Anonymous
what king of software you all us
Qt Creator with Cmake on Arch Linux. VS 2013 on Windows.
Anonymous
hello everyone i need some advice....when it comes to understanding objects and classes in C++, am encountering difficulty because i haven't covered structures and unions in C, should I study first structures and unions in C in order to understand objects and classes in C ++ better?
Anonymous
C++ classes are kind of like C structs with associated member functions
Anonymous
What can I read after I finish reading Effective C++? I am a new. I read C++ Primer Plus, C++ Primer and Effective C++.
Anonymous
What can I read after I finish reading Effective C++? I am a new. I read C++ Primer Plus, C++ Primer and Effective C++.
If you have read those, create something. Aything. Apply what you have learned so far. You will know what you need to do next.
Anonymous
Then you can learn about Boost Libraries and GUI Toolkits.
Roxifλsz 🇱🇹
What can I read after I finish reading Effective C++? I am a new. I read C++ Primer Plus, C++ Primer and Effective C++.
You have already read three books on C++? In my opinion you should start making some actual programs to gain some practical knowledge
Anonymous
Stop reading and practice
Liam
What can I read after I finish reading Effective C++? I am a new. I read C++ Primer Plus, C++ Primer and Effective C++.
Basically speaking, programming helps people to solve things that require repeating and mechanical works. Hence, look around your life, find something that is complicated but could be well defined, and implement it with C++. For example, starting a program to help you yourself for striving for your tikets back home during 春运.
Anonymous
Anonymous
Any body know how to do this
Anonymous
With file streams
Anonymous
In c language
Anonymous
Pls help me
Anonymous
Hello developers
NinuX
Hi guys, I have a little problem with OOP & Boost.asio. I'm trying to pass a reference of io_service to the constructor, and I get this compilation error:
NinuX
https://pastebin.com/VdKTQRd2 And here the code
NinuX
Please quote me to get the notice Thanx in advance
Liam
https://pastebin.com/VdKTQRd2 And here the code
As you could find in the screen shot of the compilation error, you might be noticed that you code calls a protected constructor of std::basic_ostream, which is not allowed. As for std::basic_ostream, the only public constructor is of the signature explicit basic_ostream(__streambuf_type* __sb);, which means that you have to pass a pointer to streambuffer when you are trying to construct the std::basic_ostream objects. In your code, the class Client has a data member typed in std::ostream, which is a derived class from std::basic_ostream. Since you never construct this data member explicitly, the compiler will then try to construct it by default initialization, and hence the default constructor (protected) is called. To solve the problem, construct the std::ostream object with a valid streambuffer object.
William
hi guys
William
well im getting this error while trying to compile a alotcoin source code in the mac
William
clang: warning: argument unused during compilation: '-pthread' Undefined symbols for architecture x86_64: "qt_mac_execute_apple_script(QString const&, AEDesc*)", referenced from: Notificator::notifyGrowl(Notificator::Class, QString const&, QString const&, QIcon const&) in notificator.o ld: symbol(s) not found for architecture x86_64
William
anyone have any idea?
William
not much on google about it
Andrea
Spam
Raj
Spam
👍👍👍
William
clang: warning: argument unused during compilation: '-pthread' Undefined symbols for architecture x86_64: "qt_mac_execute_apple_script(QString const&, AEDesc*)", referenced from: Notificator::notifyGrowl(Notificator::Class, QString const&, QString const&, QIcon const&) in notificator.o ld: symbol(s) not found for architecture x86_64
William
anyone ?
Liam
/warn spam
William
ok
William
qt_mac_execute_apple_script is a function that i dont have a libary linked for?
William
the pthread is just a warning anyways
William
yes ok so i need to find what libary im missing thats whats weird for me
William
hey actally
William
found the funcion in the code and commented it out
William
compiled fine
harry
🤔
harry
you can always write i=i+1 if it bothers you
harry
I suppose a decent compiler will turn it into an increment anyway
Anonymous
How to compile C++ with clang on VSCode? Do I need an extension?
Isc
Nope, create build in launch
Isc
And configure it to use clang
Anonymous
Nope, create build in launch
How to do this? Say more please.
Isc
Search for how to configure gcc
Isc
And change gcc to clang