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

  • Home
  • SEARCH
  • 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 6227207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:10:30+00:00 2026-05-24T09:10:30+00:00

Suppose I have a class like this: class MyClass { private: vector<MyOtherClass> myMember; public:

  • 0

Suppose I have a class like this:

class MyClass {
    private:
        vector<MyOtherClass> myMember;
    public:
        MyClass(const YetAnotherClass& myCollection);
}

MyClass::MyClass(const YetAnotherClass& myCollection) {
    myMember = convert(myCollection);
}

Or, in other words, I have a class with a member that’s some other data converted to be used afterwards.

Now, the weffc++ flag helps catch some stupid mistakes and makes the compiler a lot more helpful. At the same time, I like Wextra because it forces me to fix my mistakes.

The problem is that the code doesn’t compile (“MyClass::myMember should be initialized in the member initialization list”) and I dunno how to get around it. I guess I could make the myMember a pointer and set it to NULL but I’d rather not do that. I also can’t find a way to disable the warning, though I’m not sure that would be a good idea either.

I’m using GCC 4.5.2, if it makes any difference.

So, how should I go about this?

  • 1 1 Answer
  • 2 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-24T09:10:31+00:00Added an answer on May 24, 2026 at 9:10 am

    You’re not actually using a member initialization list in this instance.

    To use the member initialization list in this case, your constructor implementation would look like this:

    MyClass::MyClass(const YetAnotherClass &myCollection) 
    : myMember(convert(myCollection))
    {
    }
    

    The member initialization list is a comma separated list of member variables after the colon. Multiple member initializations would look something like this:

    class MyClass
    {
    public:
        MyClass();
    
    private:
        SomeType someMember;
        SomeOtherType someOtherMember;
        AnotherType anotherMember;
    };
    
    MyClass::MyClass() :
        someMember(a),
        someOtherMember(b),
        anotherMember(5)
    {}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a function defined like this: class Foo() { public: void bar(MyClass*
Suppose I have simple class like: class MyClass { private $_prop; public function getProp()
Suppose I have a class like this: public class Car { private double distanceDriven;
Suppose I have a class like this: class Owner { private: long m_Id; QString
Suppose you have a simple class like this: class foo{ private: int* mData; int
Suppose I have something like this: class A { public B mem; public int
Suppose I have a class like this: function myClass(q) { this.someFunction = function(e) {
Suppose I have a class like this: public class ThingManager { List<SomeClass> ItemList; public
I have a class like this public SomeClass { private List<string> _strings = new
Let's suppose I have this object: [Serializable] public class MyClass { public int Age

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.