#ifndef BASE_H
#define BASE_H

class base
{
public:

	base();

	struct baseInfo
		{
			int SlotCount[4];


		};

private:


protected:

	
};

base::base()
{
}


#endif

This is my header file, but how do I access the struct and its members through an object of the base class(through main)? I cant find anything helpful through google search.

#include <iostream>

#include "base.h"

int main()
{

	base obj;

	obj.baseInfo::SlotCount[0] = 5;



	system("PAUSE");

	return 0;
}

This compiles fun but gives me an error after running it.

Run-Time Check Failure #2 - Stack around the variable 'obj' was corrupted.

Thanks

> obj.baseInfo::SlotCount[0] = 5;
> This compiles fun but gives me an error after running it.

It should not compile (though IIRC, microsoft compilers just give a warning that memory would be corrupted and proceed to generate incorrect code that will corrupt the memory - on the stack in this case).

The name of a nested class is local to its enclosing class. To use the name of the nested class outside the enclosing class, qualify it with the name of the enclosing class.

int main()
{

	base obj;
	//obj.baseInfo::SlotCount[0] = 5; // error

	base::baseInfo info_object ;
        info_object.SlotCount[0] = 5 ; // fine

}

Also, declare the constructor as inline if you are going to define it in the header file. Else, you will get a linker error (constructor is multiply defined) if you #include the header in more than one translation unit.

You may also want to search this forum to discover the implications of using system("PAUSE"); in your code.

Edited 6 Years Ago by vijayan121: n/a

Thanks!

ya, I know system pause is windows dependent, but im not trying to write an application that is going to be used. Just teaching my self about inheritance and all that fun stuff. I usually use cin.ignore(); and cin.get(); before my return in main.

This question has already been answered. Start a new discussion instead.