-
March 1st, 2021, 02:38 PM
#16
Re: Template class inside a vector
OK I'll delete your new thread.
Victor Nijegorodov
-
March 1st, 2021, 02:53 PM
#17
Re: Template class inside a vector
-
March 1st, 2021, 02:58 PM
#18
Re: Template class inside a vector
Originally Posted by OneEyeMan
Hi
I will need to use union with int, double and std::string.
You can create a union of these 3 types using std::variant. If you declare a variable of that union type, you can check which of the types is stored in the variable using std::visit. You will need C++ 17 to do this.
-
March 1st, 2021, 08:15 PM
#19
Re: Template class inside a vector
If you haven't used an Object Relational Mapper (ORM) before you may want to check it out. I see a few available for c++. If they are anything like the EF Core ORM for C#, they will build the equivalent of vector<TableRow<T>> for you.
Search google for 'orm for c++'.
-
March 2nd, 2021, 04:15 AM
#20
Re: Template class inside a vector
So it loooks like I will need to use union with int, double and std::string.
NO. Don't do it. Don't use a std::string (or any non POD type) in a union. If you want these three types, use a std::variant with C++17.
I know you said you use C++11, but that is now over 9 years old and the current standard is C++20. I strongly urge that the compiler(s) are updated to be at least C++17 compliant.
Last edited by 2kaud; March 2nd, 2021 at 04:19 AM.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|