Anonymous
I think yes. It is located in the header file.
Creating it in the header file is wrong. The solution given by @itsmanjeet won't work for that case. There is no way to do this in C which doesn't have default initializers or constructors. So you must instead provide an init factory function which should be called every time you want a struct object to be initialized. This is the only recommended way
Anton
Anton
Deleted Account
If I set the fd of the socket to non-blocking mode, and then I use sendmsg to send fd to another process, do I still have to deal with the non-blocking unsent complete error(EAGAN?)
isaac
How do I write a C program that formats information entered by the user;
Enter intem number:50
Enter unit price:1000
Dr
You actually read the input by specifying format like %d, %f or %s etc
Ammar
Anonymous
Hello, thx for allow me to get in, have a nice weekend!
Laopigo
Can i do something like this?
char *s;
if (something) {
static char buffer[64];
// do something with buffer
s = buffer;
}
// do something with s
Ammar
ᎯᏏᎴυᎱᎱᎯᏂ𓅓.
Write a program in codeblocks to find the product of two floating point numbers and to display it.
The inputs should be entered by the user.
Kunal
Int number;
If((number & 1 )==0)
Someone can explain me this line ?
Ammar
At a glance, the code looks sane to me. Can you show your debugging detail?
Also, did you call send() properly from the other socket side?
Ammar
Alright, something went wrong. I retract my old sentence.
char data = recv(client_sock, client_message, sizeof(client_message), 0);
is not the right thing to do. recv() returns a ssize_t, not a char.
Also the
f << data
is basically printing the return value of recv(). Not the buffer that the recv() writes to memory.
You need to use
f << client_message
instead.
Ni
class A {
public:
A(A && rhs) noexcept;
A& operator=(A && rhs) noexcept;
A(int i): val(i) { std::cout « "hello" « "\n"; }
private:
int val = 0;
};
A::A(A&& rhs) noexcept: val(rhs.val) {
std::cout << "Move constructor." << "\n";
}
A& A::operator=(A && rhs) noexcept {
val = rhs.val;
std::cout << "Move-assignmemnt constructor." << "\n";
return *this;
}
A foo() {
A ret(5); // expression 1
return ret;
}
int main() {
A a = foo();
return 0;
}
Guys, I need some help here:
The above snippet gives hello on output, which was given by expression 1, so I wonder:
1. how did `a` in main function got initialized? It does not use move or move-assignment consturctor, and since copy and copy-assignment constructor is deleted, they are not used either
Jacky
u can use the move-assignment explicitly
Jacky
compiler would optimize the copy semantics
Jacky
r u use the clang compiler?
Ni
我是大娃
Jacky
u can define the copy constructor and assignment, check if can be used
Ni
我是大娃
why always use 'foo' and 'bar' as examples?
Jacky
can u close the compiler optimization?
Jacky
https://www.google.com/search?q=g%2B%2B+optimization+level
Jacky
maybe -std=c++11?😂
Anonymous
yep
Jacky
default maybe the c++2x level😂
Milwaukee
Good people lm having trouble with my code l need it to out put a 3x2 matrix lm not sure were exactly am I getting it wrong
Milwaukee
#include <iostream>
using namespace std;
int main ()
{
int m,n;
int a[3][2];
cout<<"Enter the number of rows"<<endl;
cin>>m;
cout<<"Enter the number of columns"<<endl;
cin>>n;
cout<<"Enter the Elements in Table"<<endl;
for ( int i = 0; i < m; i++ )
{
for ( int j = 0; j < n; j++ )
{
cin >>a[i][j];
}
}
for ( int i = 0; i < m; i++ )
for ( int j = 0; j < n; j++ )
{
cout << "a[" << i << "][" << j << "]: ";
cout << a[i][j]<< endl;
}
return 0;
}
Jacky
the maximum of m is 3 and n is 2, maybe the input m or n is out of range?
Ni
Jacky
i tried…
Jacky
only the default constructor is called…
Jacky
https://stackoverflow.com/questions/5918312/what-rules-to-follow-for-a-function-to-use-nrv-optimization/5918369#5918369
Anonymous
Jacky
what is difference with the NRV?
Anonymous
what is difference with the NRV?
RVO is a special form of copy elision. It is usually used to refer to the copy elision optimization performed by the compiler when you return a named local variable/temporary from a function and use it to initialize another variable of the same type. But before C++17, you still required an accessible copy or move constructor.
Post C++17, this optimization is mandatorily required and is hence not considered an optimization. So even if a class does not have an accessible copy or move constructor, the compiler can perform the copy elision. Thus copy elision is the proper way to refer to this rather than as an optimization which may or may not be performed by the compiler.
Jacky
i use the -std=c++11 only call Default Constructor, btw
Jacky
if delete the copy and move semantics, compile is error😂i guess it use the NRV
Jacky
c++17 is error, btw
Jacky
env is wsl for ubuntu20LTS
Anonymous
c++17 is error, btw
Am not sure what you tried. Here, try this code in both C++11 and C++17
class A{
public:
A(const A&) = delete;
A(A&&) = delete;
A(int a) : i(a){}
private:
int i = 0;
};
A foo(){
return A(5);
}
int main(){
A obj = foo();
}
This code would compile fine in C++17 but would give you an error in C++11 about inaccessible copy/move constructor
Shayan
Create a function that checks the Array overflow condition before insertion.
[An overflow error occurs when one attempts to append the array using an index value
greater than the array size]
Jacky
copy and move assignment all delete, btw😂
Muyi
that shouldn't be happening
Shlok
Anybody have code of Infix to prefix expression GUI code....!?
Jacky
compile in c++17 of course
Deleted Account
Deleted Account
Suka
Anonymous
hello folks, what vim plugins are you using ?
innocent
C++
hi guys, i was learning >> operator overloading in c++, but i found a weird thing that this line of code would compile in c++11 to c++17 standard but not c++20
C++
this is weird cuz i thought those standards are backward compatible
C++
wait i cant post media content
C++
ok so here's the code that i found the problem
C++
try compile that under C++20, it wont work, but for c++11, c++14 and c++17, they all work
Ni
void push_back(std::string&& str) { // 1
data->push_back(std::move(str));
}
void push_back(std::string&& str) { // 2
data->push_back(str);
}
Guys, I've tried to implement a vector like class and I've got some problem implementing the move version push_back:
* Are the above two member function identical?
* Since the str argument is already a rvalue reference, so I soppose it's redundant to use std::move to convert str, and function 2 is enough, am I right?
Anonymous
Can you guys please
give me some c++ project ideas for college?
Anonymous
Anonymous
Ni
Anonymous
Hi there
How do vector::at function works
Ammar
yes
Ok, here is the answer...
You only need to handle EAGAIN from the socket that is marked as non-blocking.
The socket in another process does not need to care about EAGAIN *if it is not marked* as non-blocking.
Anonymous
what have imgui have develoop