CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20
  1. #16
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Template class inside a vector

    OK I'll delete your new thread.
    Victor Nijegorodov

  2. #17
    Join Date
    Aug 2002
    Posts
    756

    Re: Template class inside a vector

    Thx.

  3. #18
    Join Date
    Feb 2017
    Posts
    677

    Re: Template class inside a vector

    Quote Originally Posted by OneEyeMan View Post
    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.

  4. #19
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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++'.

  5. #20
    2kaud's Avatar
    2kaud is online now Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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)

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured