Error 1 Error C2614
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up error C2614: 'ChildClass' : illegal member initialization: 'var1' is not a base or member up vote 9 down vote favorite 3 I am getting the following error in C++: error C2614: 'ChildClass' : illegal member initialization: 'var1' is not a base or member Class Base { protected: int var1; public: Base() { var1=0; } } class Child : public Base { int chld; public: Child() : var1(0) { chld=1; } } I feel what I have done is as per OO protocol. Here var1 is a data member of Base class with protected as the access specifier. So It can be inherited and it would become private in child. Don't understand why am I getting the error? Can anyone please help me in this? Thanks. c++ inheritance parent-child share|improve this question edited Apr 13 '12 at 19:33 Ben Voigt 202k21238454 asked Apr 13 '12 at 9:31 codeLover 1,03543474 2 You also have a bunch of errors in your code: Class Base should be class Base. You're missing semicolons after each class. –Mysticial Apr 13 '12 at 9:36 Why do you think "it would become private in child"? –Ben Voigt Apr 13 '12 at 19:33 add a comment| 2 Answers 2 active oldest votes up vote 17 down vote accepted It doesn't work for the exact reason the error message provides you: you can only use initializer lists with direct members or base classes. In your case, you don't even need to initialize var1, since Base::Base() will be called by Child's constructor, which will set var1 to 0. If you want a different value, you'll have to overload Base constructor and call it explicitly: class Base { protected: int var1; public: Base() : var1(0) { } Base(int x) : var1(x) { } }; class Child:public Base { int ch
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Illegal Member initialization up vote 5 down vote favorite 2 I am using this pretty simple class without using any inheritance. class http://stackoverflow.com/questions/10138424/error-c2614-childclass-illegal-member-initialization-var1-is-not-a-base A { int a; int b; public: A(int x, int y) { a = x; b = y;} A() :A(0,0){}; ~A(){}; } ; int main () { A a1, a2(5, 7) ; } I get this error. error C2614: 'A' : illegal member initialization: 'A' is not a base or member There are similar questions on SO but they relate to inheritance. Can someone explain the reason and what does standard say about that? EDIT: http://stackoverflow.com/questions/12988048/illegal-member-initialization It would be better if someone elaborate more on the forwarding constructor and this feature in C++11. c++ oop constructor member-initialization share|improve this question edited Oct 20 '12 at 11:50 asked Oct 20 '12 at 11:40 Coding Mash 3,20451642 This compiles fine for me but not in gcc –0x499602D2 Oct 20 '12 at 11:45 looks like you're using Visual Studio 2010(or previous), it doesn't work in VS2010 even. I heard that more features of C++11 have been added to SP1, and VS2012 but I am not too sure. –Aniket Oct 20 '12 at 11:48 See n1986. –Mankarse Oct 20 '12 at 11:52 Why the downvote??? –Coding Mash Nov 21 '12 at 4:10 Possible duplicate of C++11 calling constructor from constructor of same class type –Florian Castellane Jul 21 at 12:14 add a comment| 5 Answers 5 active oldest votes up vote 4 down vote accepted If you can use C++11, you could initialize A() from A(int, int). This is not possible in C++03, where you have to write two separate constructors. If you want your code to work in C++03, you have two options: Create a function init(int, int) and call it from each of your constructors. This is a good choice if your constructor does a lot of work. Dupli
Sign in Pricing Blog Support Search GitHub This repository Watch 4 Star 13 Fork 1 Gronis/OpenEcs Code Issues 2 Pull requests 0 Projects 0 Pulse Graphs New issue OpenEcs in Visual Studio 2013 #8 Closed DJuego opened this Issue Dec 1, 2015 · 5 comments Projects None yet Labels None yet Milestone No milestone Assignees No one assigned 2 participants DJuego commented Dec 1, 2015 I am interested in building with OpenEcs in a Visual Studio 2013 environment. However... \inc\OpenEcs\single_include\ecs.h(917): error C2621: 'ecs::details::BaseEntityAlias::entity_' : illegal union member; type 'ecs::Entity' has a copy constructor \inc\OpenEcs\single_include\ecs.h(913): error C2065: 'entity_' : undeclared identifier \inc\OpenEcs\single_include\ecs.h(1066): error C2614: 'ecs::details::BaseEntityAlias' : illegal member initialization: 'entity_' is not a base or member \inc\OpenEcs\single_include\ecs.h(1068): error C2039: 'entity_' : is not a member of 'ecs::details::BaseEntityAlias' \inc\OpenEcs\single_include\ecs.h(905) : see declaration of 'ecs::details::BaseEntityAlias' \inc\OpenEcs\single_include\ecs.h(1068): error C2614: 'ecs::details::BaseEntityAlias' : illegal member initialization: 'entity_' is not a base or member ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========` Any possibility? Thanks! Owner Gronis commented Dec 1, 2015 Hi DJuego and thanks for reporting an issue! I haven't tried to compile the project with VisualStudio 2013. But I'm using a build server called appveyor that runs Visual C++ (Visual Studio's C++ compiler), and it compiles the project fine. Perhaps the compiler in Visual Studio 2013 is older than the compiler used by appveyor. The Entity uses a trivial constructor right now, but implemented manually. I've removed the copy constructor definition which might solve your problem above (not sure t