Jump to content
  • Advertisement
Sign in to follow this  
ProPuke

ctor initializer list inherited variables

This topic is 4950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

struct base{
  int a;
};
struct thing:base{
  thing():a(4){}
};
main.cpp: In constructor `thing::thing()': main.cpp:5: no type named `a' in `struct base'
struct base{
  int a;
};
struct thing:base{
  thing():base::a(4){}
};
main.cpp: In constructor `thing::thing()': main.cpp:5: no type named `a' in `struct base' Speaks for itself. Syntax problem on my part? g++ problem? help?

Share this post


Link to post
Share on other sites
Advertisement

struct base{
base(int A) : a(A) {}
int a;
};
struct thing:base{
thing(int A) : base(A) {}
};




HTH,
Jim.

Edit : Devon, huh? I was born and raised in Tavistock and Exmouth. Small world, huh?

Share this post


Link to post
Share on other sites
Huzzah! thanks man.
Heh from Barnstaple here, although kinda in London atm (maybe I should change gamedev to reflect that)
Small world? Won't you believe it. 99% of the population are just white noise in the program of life (npc's to pad it out, make it look like there's more poeple playing) So yeah in the end it's smaller than you think ;]
again cheers

Share this post


Link to post
Share on other sites
The problem is (AFAIK) that you are inheriting privately (the default, even for structs). Try it with "struct thing:public base{" instead.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!