Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6025687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:20:12+00:00 2026-05-23T04:20:12+00:00

class A{ private: std::vector<class X> flavor1 std::vector<class X> flavor2 public: void useVectorOfX(std::vector<class X> someflavor){

  • 0
class A{

private:

  std::vector<class X> flavor1
  std::vector<class X> flavor2

public:

  void useVectorOfX(std::vector<class X> someflavor){
      ...  // same logic for both flavors
  }    
}

Now I want to call useVectorOfX() from another class, giving it either flavor1 or flavor2 depending on need. I can think of three ways –

Way 1: Use Getter Methods; but it seems unnatural for class A to get its own data through a Getter Method.

class B{

public:

  A *a = new A();
  a->useVectorOfX(a->getFlavor1());
}

Way 2: Make the two vectors public (dirty)

Way 3: Separate Methods?

class B{

public:

  A *a = new A();
  a->useVectorOfXForFlavor1();
  a->useVectorOfXForFlavor2();

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T04:20:12+00:00Added an answer on May 23, 2026 at 4:20 am

    What about way 1 in a more descriptive format:

    class A {    
    public:
        enum {
            flavor1 = 0, // used as array index, first element must be zero
            flavor2,
        } vector_flavor;
        static const int number_of_flavors = 2;
    
        void useVectorOfX(vector_flavor flav){
            std::vector<class X> someflavor& = vectors[flav];
            // ...
        }
    private:        
        std::vector<class X> vectors[number_of_flavors];
    }
    
    A object; // lol
    object.useVectorOfX(A::flavor1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Option 1: class B{//}; class A { public: void Funcs(); private: std::vector<A> vecA; };
template <typename T> class Stack { private: std::vector<T> elems; // elements public: Stack(); //
I have these classes: class Base { ... private: std::vector<X> v; }; class Derived
I have a class like this: class MyClass{ public: MyClass(int Mode); private: std::map <
class String { private: char* rep; public: String (const char*); void toUpper() const; };
class B{ private: void DoSomething(); } class W{ private: class D: public B{ }
I've got a class declared like this: class Level { private: std::vector<mapObject::MapObject> features; (...)
I want to fill std::vector (or some other STL container): class Foo { public:
I have the following problem. Consider the classes class face { virtual std::vector<ptr>& get_vertices(void)
I have a class with a std::vector data member e.g. class foo{ public: const

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.