SHP
Just used it at my beginning of c programming for bout 45 mins, then i switched to codeblocks and 1 year later vscode
Aakash
Aakash
Pavel
#
Solve my problem
Anonymous
Will Rust Replace C++ in Future ?
SHP
nope i think
Terrorist
What time is it now?
Anonymous
Does c++ have special advantages over rust?
Anonymous
Ighor
anyone need a bot that automatically remove that 💩?
Ighor
nice job but it is annoying to see that spam stays time to time here
Dima
Dima
nothing personal, but who knows what this bot would do
Ighor
nothing personal, but who knows what this bot would do
bots don't have access to remove messages older than 24h, and my bot don't need rights to ban, so it can't harm. I can explain how it works, but you won't be able to use its code, since it is running in custom engine
Egro
void swap(int& x, int& y);
int main()
{
using namespace std;
int a = 45, b = 35;
cout<<"Before Swap\n":
cout<<"a = "<<a<<" b = "«<b<<"\n":
swap(a,b);
cout<<"After swap with pass by reference\n"; cout<<"a = "<<a<<" b = "<< b <<"'\n";
void swap(int& x, int& y)
{
int temp:
temp = x;
x = y;
y = x;
}
Egro
this code will not run... help me find out why
Jonathan
y = temp
Anonymous
Hello, can anyone help me to eliminate the Imaginary numbers in this code
Egro
Egro
y = temp
damnn, silly me. its was like a big "duh" once i saw it too. mannn, super thank you.
neovstan
UnO1
can someone help me with this ...
"write a program that enters a number and determine if the number is prime or composite using ELSE IF ONLY, without using loops"
UnO1
C++
Egro
Mr
浩
浩
Without nan as an element of number, scalar operator on number cannot be closed, you dont want to let cpp throw an exception when calculate 0/0.
Anonymous
Anonymous
Rust is strong too
Anonymous
Anshul
class A
{
public:
A()
{
}
private:
int c;
B obj; //Line 1
//B obj(c); // Line 2
};
class B
{
public:
B(int t){
k = t;
}
private:
int k;
};
Here when i am trying to create an object of class B in class A i get error in trying it both way i.e. Line 1 and Line 2. as B doesn't have any default constructor i would need to call the parametrised constructor by passing an int. But I am getting error "B doesn't name a type"
Anshul
what is the right way to do it
SHP
forwarding declaration may help
SHP
it's because by the time B is used in A, You have no idea what B is, so put a single declaration of
class B;
before class A will solve this, maybe
SHP
@Pareekc1
SHP
ah, just noticed you also didnot construct B in a right way, A's default ctor cannot correctly default construct B
Anshul
with forward declaration when i do this , B obj(c);
i get this error
error: ‘c’ is not a type
Anshul
SHP
it's because it identified obj of a function taking c type parameter, returning B type, which we often call most vexing parse
SHP
and you should construct B before function body after parameter list of ctor, not where it's declared
SHP
Let me give an example here:
struct A { ... };
A x; // default construct
A y(); // declare y as a function of no parameters and returning A.
Anshul
SHP
so any y.A_function() / y.A_member will trigger compilation errors
Anshul
Anshul
Anshul
Sen Sovisal
What is "include<stdio.h>" mean? please give the answers.
SHP
in your example, you may change A's ctor as:
A() : c{0}, obj{c} {}
A(int x) : c{x}, obj{c} {}
or a one-liner:
A(int x = 0) : c{x}, obj{c} {}
Anshul
Sen Sovisal
Anshul
also with obj why are we using two {} {} instead of just obj{c}
SHP
I'd prefer brace-initialization when both are ok, but there're differences when you have a ctor passing initializer_list, like std::vector<int> v{1, 2} and std::vector<int> v(1, 2)
Anshul
Anshul
Anshul
SHP
I assume a possible way is to make the calculation a private function, and then passing to c{func()}, rather than in ctor body
Anshul
Okay
Anshul
class A
{
public:
A() : obj{fun()}
{
}
private:
int c;
B obj;
int fun(){
if(condition) { c = 0;}
else {c = 1;}
}
};
Shadow
Rule #2
This program was asked by my lecturer..
I want full program..
Anshul
Anshul
field ‘obj’ has incomplete type ‘B’
SHP
and fun() need to return c, I think
SHP
class B;
class A {
....
};
class B {
....
};
Anshul
SHP
most simple fix would be move B before A, lol
SHP
Ah, I made mistakes here, plz ignore it
SHP
forwarding declaration does not work fine here, a big change is needed maybe
SHP
class B {
public:
B(int);
private:
int k;
};
class A {
public:
A() : obj{fun()} {}
int c;
B obj;
int fun() { return c = 1; }
};
B::B(int t) : k{t} {}
Mr