BinaryByter
Raul
And I don't know how many classes I will be storing if that makes sense?
BinaryByter
add a try around each call, if you aren't sure about the lifetimes though
BinaryByter
Anonymous
who help me how to make this?
You can make use of switch case something like this:
#include <cstdlib>
#include <iostream>
using namespace std;
void doSomething() { cout << "Option 1 chosen" << endl; }
void doSomethingElse() { cout << "Option 2 chosen" << endl; }
void exitNow() {
cout << "Bye!\n";
exit(-1);
}
int main() {
int choice;
while (true) {
cout << "\nChoose something ->\n";
cout << "Option 1\n";
cout << "Option 2\n";
cout << "Exit with 3\n\n";
cout << "Choose option: ";
cin >> choice;
switch (choice) {
case 1:
doSomething();
break;
case 2:
doSomethingElse();
break;
case 3:
exitNow();
break;
default:
cout << "Wrong choice!\n";
return -1;
}
}
return 0;
}
Raul
Essentially, I am trying to go around a reference pointer. I just want a lightweight templated class that can set and get. I feel if I can do it this way, I can eliminate a ton of unneeded code base.
BinaryByter
why do you want to avoide a reference?
Raul
Essentially, Class A has a setter name setVar(), Class B has a setter named updateVar(), etc. And If I can pass them into this controller, then I can create a function for each of the classes that have setter and getters and update them this way.
BinaryByter
oh I get that
BinaryByter
then you should accept an infinite amount of functions
BinaryByter
no need to wrap them in templates
Rafi Faseeh
Raul
I am not wanting to avoid a reference. I am trying to avoid a reference pointer that is in our code base. Essentially, we create an Object, and an imageViewer. Well say the GUI needs to update a value on the gui, the object, and the imageviewer. We wrap each of them into a ref_ptr<Object>, ref_ptr<imageViewer>, ref_ptr<GUI>, then, we throw them into a group of reference pointers. So, group(obj,imgV,gui); then if we want to set the value group->setVal(20); then they all get updated.
BinaryByter
why absolutely a reference pointer?
Raul
It's from openscengraph: https://github.com/openscenegraph/OpenSceneGraph/blob/master/include/osg/ref_ptr
Anonymous
I am having a hard time understanding few OOP stuffs
1. Why use a constructor and destructor?
2. Difference between inheritance and abstraction
Anonymous
^
Raul
However, it has been modified on my end. It's just something my coworker did for some reason.
BinaryByter
BinaryByter
2) there is none
Anonymous
Ann0nB0t
Ok
Ann0nB0t
meis
BinaryByter
wut?
BinaryByter
jmp is not an exception handler
BinaryByter
its an exception creator, maybe
BinaryByter
*never use goto pl0x*
Dima
always goto!
Anonymous
I think I understood OOP finally xD
Anonymous
It was not that hard xD
BinaryByter
Nobody can understand OOP
BinaryByter
OOP is that thing that only the gang of four knows
Anonymous
Well right
BinaryByter
xD
BinaryByter
don't worry, OOP code is messy
BinaryByter
you should find a healthy dose of OOP and procedural and functional
BinaryByter
+ OOP tends to be bloat if you have big structs
Anonymous
It took me a bit time to understand what is constructor, what it does, and OOP terms like abstractions and polym
Anonymous
So where is what I did,
This is a simple class:
#include <iostream>
class baseClass {
public:
void doSomething() { std::cout << "Hey!\n"; }
};
int main() {
baseClass obj;
obj.doSomething();
return 0;
}
and here is same with a constructor
#include <iostream>
class baseClass {
public:
baseClass() { std::cout << "Hey!\n"; }
};
int main() {
baseClass obj;
return 0;
}
So what constructor did is just called the that method automatically
BinaryByter
when you CREATE an object, the constructor is called automatically
BinaryByter
try giving an argument to your constructor
professor
I am compiling my project as this , because I want a smaller exe, but I always get the obj files
am only getting the obj files, but never the exe
cl *.cpp /c /O1 /GS- /Oi- /link /NODEFAULTLIB /ENTRY:main /MERGE:.rdata=.text *.obj user32.lib kernel32.lib /FE project.exe
Anonymous
^ WTH is that
Pankaj
Okay😊
Raul
This is going to be an annoying question, but where does one start learning about template programming? I feel that the majority of people here are on another level. However most of the online resources I have found have been subpar. Where can I learn more about it?
Anonymous
done
psy4
Anonymous
how to open embedded terminal in gedit?
Liam
Liam
Anonymous
sorry my setup are gedit and g++.
Anonymous
should I start reading from chat 1 to learn?
Anonymous
https://pastebin.com/DjX2HYY3
how do i fix the non int input
Anonymous
🥶
Anonymous
get it. Thanks
Kumar Vipin
Anonymous
yes
Anonymous
Anonymous
what are you using
Anonymous
why you include stdio.h
Anonymous
was from an online compiler
Anonymous
i deleted it
Kumar Vipin
Milk what you are trying to do 🤔
Anonymous
fixing a possible user error
Anonymous
lets say someone enters a non int
Anonymous
for an input asking for an int
Anonymous
the try and catch?
Kumar Vipin
Kumar Vipin
the try and catch?
Put input section in try block and make an exception block if there is a value error
Anonymous
thats what i was trying to do and someone else told me something different
Kumar Vipin
Anonymous
im getting the same problem
https://pastebin.com/3U736jG9
code just ends without going through the catch
Anonymous
🤬
Kumar Vipin
🤬
while (cin >> acc.numInput)
How could you do this ^^^^