MᏫᎻᎯᎷᎷᎬᎠ
class B; class A; class A { B* b; A():b(new B)//error: using incomplete type }; class B{ A* a . . }
Dima
you can't do anything but define that class
Dima
B* b; will be okay, but anything else will not work
MᏫᎻᎯᎷᎷᎬᎠ
B* b; will be okay, but anything else will not work
Yeah It'll cause like a infinity space
MᏫᎻᎯᎷᎷᎬᎠ
B needs A needs B needs A.......
MᏫᎻᎯᎷᎷᎬᎠ
I used forward declaration to write B* b;
MᏫᎻᎯᎷᎷᎬᎠ
But Whenever I want to define it It says "Incomplete type"
MᏫᎻᎯᎷᎷᎬᎠ
I mean Wtf
MᏫᎻᎯᎷᎷᎬᎠ
Functions declaration works perfectly
MᏫᎻᎯᎷᎷᎬᎠ
void foo1(); void foo2(){ foo1() } void foo1(){} That's perfect
Mihail
Why would you need to do that with classes? Give more context because I'm 99% certain there's a better way to achieve whatever you're trying to do
Anonymous
class B; class A; class A { B* b; A():b(new B)//error: using incomplete type }; class B{ A* a . . }
Put the member initialization list in the cpp, create the constructor function definition in cpp and include class b header file. Remember to use #pragma once in header files.
MᏫᎻᎯᎷᎷᎬᎠ
Anonymous
I used forward declaration to write B* b;
When you use forward declaration, it will only know that the type exist. When you use new B, it have to know how much memory to allocate which forward declaration won't tell the compiler.
Elnee
If I want to pass static int const to function what should I choose as a function parameter? 1. static int 2. const int 3. int Sorry if it's stupid question. Just all that variants work and I don't know what is better and why.
Elnee
You Can't declare a static variable as a parameter 2 & 3 are legal
Okay, thanks. So I can pass const int static to function that accepts int?
MᏫᎻᎯᎷᎷᎬᎠ
Elnee
Thank you for answer
Anonymous
Does any one here knows how to contribute to open source softwares
BinaryByter
Yes
Anonymous
Have you heard of gsoc
BinaryByter
Yes
Anonymous
I wanted to participate but I don't know what kind of skills in c/c++ would be required
BinaryByter
Okay
j
http://tldp.org/LDP/Bash-Beginners-Guide/html/
j
i find this introduction to bash a bit complicated
j
then, there's also this book called "The linux command line" but im not really sure if it is as complete as the resource mentioned above
Ariana
why would one want to write in bash
Ariana
i find this introduction to bash a bit complicated
which part of it? bash is a language that youll just need to try and eventually youll get it
j
it talks about some concepts which im not familiar with
j
should i go with the other book instead?
Ariana
just try it first havent tried that b4,
j
this was alright for me
you read the whole book?
Ariana
basiically
Dima
6660 members
Dima
Hell’uva lot of people
Dima
-1 lol
Anonymous
I read it
Anonymous
Hello guys! Am a newbie to the programming community. Totally green so, hoping to learn here
MᏫᎻᎯᎷᎷᎬᎠ
We hope so
Dima
Welcome
Anonymous
Thanks
olli
class B; class A; class A { B* b; A():b(new B)//error: using incomplete type }; class B{ A* a . . }
Not sure why you want it... But it works if you declare the classes first and then the implementation
olli
I did that
This was not the case in the code above
MᏫᎻᎯᎷᎷᎬᎠ
Excuse me there is a violation of rules here Indian seller
olli
I edited Like this @ollirz
#include <memory> class A; class B; class A { std::unique_ptr<B> b; public: A(); }; class B { std::unique_ptr<A> a; public: B(); }; A::A() : b{std::make_unique<B>()} {} B::B() : a{std::make_unique<A>()} {} int main() { A a; B b; } SEGFAULTS do not use You can make your example work like this. Again there is no use to this code since it segfaults
MᏫᎻᎯᎷᎷᎬᎠ
It'll compile but with segfault
MᏫᎻᎯᎷᎷᎬᎠ
Oh you edited
olli
It'll compile but with segfault
I you create an Object of A it will create B whihch will create A which will create B and so on => segfault
MᏫᎻᎯᎷᎷᎬᎠ
I you create an Object of A it will create B whihch will create A which will create B and so on => segfault
Yeah That's why I prefered declaring a pointer to A and a pointer to B
MᏫᎻᎯᎷᎷᎬᎠ
To ensure that they'll be no sagfault
olli
Yeah That's why I prefered declaring a pointer to A and a pointer to B
Yea sure, but if you allocate memory for each of them in the constructor you have the same issue
MᏫᎻᎯᎷᎷᎬᎠ
olli
So We won't allocate them in the constructor
This works class A; class B; class A { B * b; public: A(); }; class B { A * a; public: B(); }; A::A() {} B::B() {} void foo() { A a; B b; }
Johan Liebert
Please suggest me best apps to learn c++ on ubuntu?by the way im new to c++. I have studied c in codeblock. But i am looking for some more great app.
Johan Liebert
Im using gcc
Jøhn
Vim dddddddd
Johan Liebert
Is it ok??
Mat
Im using gcc
gcc is the collection of the compilers you need (fot C++ you need g++)
Mat
Codeblock and gnome builder are IDEs
Mat
Different things
Johan Liebert
Sorry I mean g++ .
Johan Liebert
I wrote there by mistake.
Johan Liebert
So please tell best compiler as well as IDE It will be helpful.
olli
Alright Thanks again olli
sure, no worries :)
Mat
So please tell best compiler as well as IDE It will be helpful.
Compilers: g++ and clang++ IDEs: Personally gnome builder
Mat
Let's see how many times i need to repeat it 😆
Prometheus
Compilers: g++ and clang++ IDEs: Personally gnome builder
If you repeat something for long enough people believe it’s true lol
Johan Liebert
Thanx
Jøhn
So please tell best compiler as well as IDE It will be helpful.
Dunno about compilers but IDEs are pure preference. I use NP++ on Windows and Geany on Linux for all my coding needs.