Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Class in a class (C++)

Name: Anonymous 2007-06-29 7:25 ID:gaE5eFHD

Lets say I have this following class:

class Settings {
public:
  Settings(char *filename);
  ~Settings();
protected:
  class Anotherclass anotherclass;
};


Upon the Constructor call 'Settings' it says error C2512: '' : no appropriate default constructor available. How do I get a class to be inside another class?

Name: Anonymous 2007-06-29 7:52 ID:97MK14mD

Remove that 'class' keyword, it's wrong.

If Anotherclass doesn't have a default constructor, you'll have to call one of its explicit constructors in the Settings's constructor initializer list.

Name: Anonymous 2007-06-29 8:05 ID:/1oDRXbD

>>1

Your C2512 error has nothing to do with putting a class inside another class. As >>2 points out, either add a default constructor Settings(); or initialise using code like Settings *s = new Settings("the filename"); rather than Settings s;.

>>2

Using the class keyword in class Anotherclass anotherclass; not wrong, though it is redundant.

Name: Anonymous 2007-06-29 8:20 ID:gaE5eFHD

>>2
>>3
Ah, thanks guys, your both pro =D
my program is working smooth as a babies ass

At this rate I should have the basics of C++ mastered in a few days =)

Name: Anonymous 2007-06-30 3:03 ID:Gvmk8ldl

>>4
correction: EXPERT PROGRAMMERS

Name: Anonymous 2007-06-30 4:53 ID:40yqKgcy

>>5
Correction: EXPERT PROGRAMMERS

Name: Anonymous 2007-06-30 5:36 ID:Heaven

>>6
Correction: EXPERT PROGRAMMERS

Name: Anonymous 2007-06-30 6:10 ID:Gvmk8ldl

>>6
>>7
lol predictable

Name: Anonymous 2009-01-14 14:59

</ThreadOver>

Name: ​​​​​​​​​​ 2010-10-22 11:30

Name: Anonymous 2011-01-31 21:31

<-- check em dubz

Name: tray 2012-03-15 1:11


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List