Thread: synthesized method 'options::options()' first required here options opts;

  1. #1
    Banned
    Join Date
    Aug 2017
    Posts
    861

    synthesized method 'options::options()' first required here options opts;

    I'm using c++11 restrictions, so I can beef up on C++, haha snicker snicker, Just want to try and make a good program in C++. (first timer, i must add)

    code to reproduse the errors.
    main
    Code:
    #include <iostream>
    #include "strt.h"
    int main(){
    options opts;
    return 0;
    }
    a header file.
    Code:
    #ifndef STRT_H
    #define STRT_H
    
    #include <vector>
    typedef struct {
    int i = 0;
    int g = 0;
    
    //to be compatible with vector.size() return data type
    unsigned long int leftoff = 0;
    char *path = NULL;
    //holds file names
    std::vector<std::string> dfile;
    }options;
    extern options opts;
    
    #endif
    the two things I do not know what about.
    the errors,
    Code:
    [userx@void stupid]$ g++ -Weffc++ *.cpp
    In file included from dummy.cpp:2:0:
    strt.h: In constructor 'options::options()':
    strt.h:18:2: warning: 'options::dfile' should be initialized in the member initialization list [-Weffc++]
     }options;
      ^~~~~~~
    dummy.cpp: In function 'int main()':
    dummy.cpp:5:10: note: synthesized method 'options::options()' first required here
      options opts;
            ^~~~
    I do not know how to fix either one. never heard tell of that synthesized method thing. Until I googled it and it looks like it gets called for all sorts of things.

    initialize a vector<string> ?

  2. #2
    Guest
    Guest
    I can't say I fully understand what you're trying to accomplish there, but things can probably be simplified. And please start indenting your code properly if you want others to read it and help. 2 spaces, 4 spaces, 8 spaces, it doesn't matter, just align things semantically.
    Code:
    struct options {
        int i = 0;
        int g = 0;
        std::size_t leftoff = 0; // Yes, you can use this type alias directly, or even std::vector::size_type
        char* path = nullptr; // Forget about NULL, in C++ it's nullptr
        std::vector<std::string> dfile{}; // This should kill the warning, though it's not strictly needed.
    };
    Now you should be able to just use the struct in your main function.

  3. #3
    Guest
    Guest
    Also, this answer on stackoverflow might be of interest. I personally haven't explicitly used the -Weffc++ flag before.

  4. #4
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by Guest View Post
    Also, this answer on stackoverflow might be of interest. I personally haven't explicitly used the -Weffc++ flag before.
    55837 – [C++11] -Weffc++: warning: 'xxx:yyy' should be initialized in the member initialization list

    buggy don't bother trying it.

  5. #5
    Guest
    Guest
    No, you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 3 of 8 options
    By apolochaves in forum C Programming
    Replies: 5
    Last Post: 08-01-2010, 05:41 PM
  2. Is there really a better of the two options I have?
    By Shamino in forum C++ Programming
    Replies: 5
    Last Post: 12-26-2007, 08:37 AM
  3. Dev-cpp - compiler options
    By tretton in forum C Programming
    Replies: 7
    Last Post: 01-06-2006, 06:20 PM
  4. 2 options.... which way should I go?
    By CodeMonkey in forum Game Programming
    Replies: 9
    Last Post: 03-18-2002, 09:20 PM

Tags for this Thread