Ausir
Amit
Hlo all
Amit
class Singleton
{
private:
static Singleton *m_singleton;
public:
static Singleton &Get()
{
return *m_singleton;
}
void Print()
{
cout << "we are inside singleclass " << endl;
}
};
Singleton* Singleton::m_singleton=nullptr;
int main()
{
Singleton::Get().Print();
Singleton::Get().Print();
Singleton::Get().Print();
Singleton::Get().Print();
}
Amit
This is one of the way to implement singleton class
Amit
But my doubt is here "m_singleton" is intialised with nullptr right....and we haven't assigned that ptr to anything
Amit
So in the end.....Get() func should return a Null obj reference isn't???
Pavel
Can you give me more details?
If the message queue implementation supports different types of messages, then it's possible. You need to refer to the documentation of the one that you use.
If you implement it yourself, you can do that either by having virtual base class or using std::variant or std::any
Ausir
Pavel
Ausir
+
Hi guys
anyone have any Idea what is this warning about?
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
its happen when I try to compile a dll
Anonymous
Can you help me solve a project
Anonymous
؟؟
Deepak....
If else
Deepak....
If else statement based questions send Me anyone
Anonymous
This is a university project that I want to solve. Can I send a picture of the project or not according to the laws???
Anonymous
The question is simple, I am in my first year at university
Hanz
Anonymous
Ok
Anonymous
Do laws forbid that?
Hanz
Anonymous
Ok , thanks
Yasas
Pradevel (Pratyush)
Yasas
Yasas
Perhaps.
But like isn't this group ment to help someone?
Anshul
*that's what I think
Yasas
That's bad.
Yasas
At least you should have asked what he wanted?
Yasas
Oh okay.
Nevermind.
Let's stop this discussion.
Anshul
Yea👍
Anonymous
hi guys i want to ask one thing
why we use pointers in c
Anonymous
just to get a valid reason for the usage of pointers in c i am asking this question
Anonymous
What programming language(s) are you familiar with?
Anonymous
Anonymous
c and python i am currently learning now
and moreover i know how to use them
i want to know its usage in real life programs
Anonymous
Oh okay. Python really isnt my strong suit ^^. Either way, pointers can be very useful for a lot of reasons but one example would be to pass something big by "reference". Like if you have an instance of a big struct you can pass a pointer to that instance in order to access its members without needing to copy the whole thing. Another thing is also the same situation and you want to modify the struct directly and not modify a copy of the struct.
Anonymous
Anonymous
Thats one of the reasons.
Anonymous
especially in big programs holding struct and stacks etc
Anonymous
Its also mich faster in execution time to only move a 4byte pointer instead of the whole struct :)
Anonymous
*much
Anonymous
Anonymous
Also as i was saying imagine you want to modify the struct. Doing a copy of it wont help there. You need to know the address in memory that you want to modify
Anonymous
Sure np. :)
Anonymous
👍😇
Anonymous
@Erarnitox thanks man
Official hooligan of Pius XII
Is there any alternative for <ncurses.h> in C++? I need to use getch() but this header throws an error
/usr/include/curses.h: In function ‘int main()’:
/usr/include/curses.h:254:8: error: expected unqualified-id before string constant
254 | extern "C" {
| ^~~
Nameful
Official hooligan of Pius XII
Official hooligan of Pius XII
#ifdef _WIN32
const char CLEAR[3] = {'c', 'l', 's'};
#include<conio.h>
#else
const char CLEAR[5] = {'c', 'l', 'e', 'a', 'r'};
#include<ncurses.h>
#endif
Nameful
And before that?
Official hooligan of Pius XII
it's the beginning of the main, here's the rest of includes
#include<iostream>
#include<ctime>
#include<string>
#include<iomanip>
using namespace std;
Nameful
Official hooligan of Pius XII
i can upload in on some pastebin in a few minutes, because such code works:
#include<ncurses.h>
int main(){return 0;}
there's some problem with my code then
Nameful
Make sure you put a semicolon at the end of the class
Nameful
Make sure it's this
class Gamer {
// code
};
And not this
class Gamer {
// code
}
Anshul
Do anyone know about prime sieve array?
I was watching a tutorial and in it the tutor was saying that the sieve array can be at max of size 10^8. Can anyone tell me why
Official hooligan of Pius XII
Jitendra
Anshul
Amit
Amit
Amit
Anshul
But can we also initialise it to nullptr. I read that it is done like initialise it with either "NULL" or "0"
Official hooligan of Pius XII
I managed to include <ncurses.h> but now this function (it doesn't matter whether there's toupper() or not, i've already checked it out):
char get_choice()
{return toupper(getch());}
gives this output:
/usr/bin/ld: /tmp/ccyF5KV8.o: warning: relocation against stdscr' in read-only section .text'
/usr/bin/ld: /tmp/ccyF5KV8.o: in function `get_choice()':
2048.cpp:(.text+0x7): undefined reference to `stdscr'
/usr/bin/ld: 2048.cpp:(.text+0xf): undefined reference to `wgetch'
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
make: *** [<builtin>: 2048] Error 1
Official hooligan of Pius XII
I've never been using getch() on linux and it looks like one big problem...
Anshul
Anonymous
Ya I got it man thanks buddy 👍
Anonymous