LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   what? --> note: synthesized method 'options::options()' first required here (https://www.linuxquestions.org/questions/programming-9/what-note-synthesized-method-%27options-options-%27-first-required-here-4175615222/)

BW-userx 10-07-2017 08:59 AM

what? --> note: synthesized method 'options::options()' first required here
 
In C++11, I have a struct here:
header:
Code:

typedef struct {
int i = 0;
int g = 0;

//to be compatible with vector.size() return data type
unsigned long int leftoff = 0;

char *path = nullptr; <-- I'm assuming that is right instead of NULL.

//holds file names
std::vector<std::string> dfile; <-- I have no idea how to initialize that

}options;


extern options opts;

Quote:

/media/data/projects/VSC/C++/codeblocks/mh5000/mh5000/options.h|21|warning: 'options::dfile' should be initialized in the member initialization list [-Weffc++]|
I got most of the list initialization (since C++11) thing figured out (kind of) except for that vector<string>, but I too am getting what that title says here in the cpp. it is not saying anything about my other struct set up the same with a lot more data in it, not yet anyways.

in the options.cpp it references this-> note: synthesized method 'options:: options()' first required here. (no space between the colons, I get a 'O' face if I keep it like that. )
Code:

options opts;
options:: options() <--- it is not a class it is a strut, don't let that little bit of knowledge fool you about my limited amount on this subject.

pan64 10-07-2017 09:37 AM

use: [noparse]options::options()[/noparse] to avoid :o faces

post at least something usable, to be able to reproduce what you are talking about. What I can see is syntactically incorrect and therefore useless. How do you think anyone will be able to tell you what's wrong with your real code?

BW-userx 10-07-2017 10:57 AM

Quote:

Originally Posted by pan64 (Post 5767353)
use: [noparse]options::options()[/noparse] to avoid :o faces

post at least something usable, to be able to reproduce what you are talking about. What I can see is syntactically incorrect and therefore useless. How do you think anyone will be able to tell you what's wrong with your real code?

that's it my whole struct just stick it in a header file and make a main then compile it.

oh for you:
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

run
Code:

g++ -Weffc++ *.cpp
gets
Code:

[userx@void gurp]$ 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;
          ^~~~


pan64 10-09-2017 12:58 AM

http://www.geeksforgeeks.org/when-do...zer-list-in-c/
https://www.cprogramming.com/tutoria...lists-c++.html
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55837

BW-userx 10-09-2017 07:36 AM

well that last one explains everything, doesn't it?
I was actually thinking of just removing that or downgrading the standardization.
thanks for that last link.

makes me wonder what -W checks are really be trusted.


All times are GMT -5. The time now is 03:11 AM.