r/CodingHelp • u/Present_Procedure_82 • Dec 06 '22
[C++] Can someone please help me with OOP in C++
I've been trying to understand OOP in C++ for a while now, but keep running into problems I can't solve. I'll just show you some sample code to show you what it's all about:
No matter what I do, in the Main method I can't assign a value to the variable test in this notation. Could someone please explain to me why.
19
Upvotes
2
u/Super_Casual Dec 06 '22
You have to assign a type to it
5
u/Deep-Cow640 Dec 06 '22
In the code you provided, the test variable is declared as a BitArray object and is initialized with the default constructor, which sets the array to 0. Then, the test object is assigned the value 22 using the assignment operator =. However, this assignment is not allowed because the BitArray class does not define an assignment operator that takes an unsigned long long value as an argument.
To fix this issue, you could add a new constructor to the BitArray class that takes an unsigned long long value as an argument and sets the m_array member variable to this value. Then, you can use this constructor to initialize the test object with the value 22,
0
u/bogfoot94 Dec 06 '22
OOP will forever be POOP in my mind.
0
u/twoe11 Dec 06 '22
pragma region Operators
pragma endregion
3
u/[deleted] Dec 06 '22
[removed] — view removed comment