Jump to content

calling up classes that are nested in another class

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
ligerz785

ligerz785

    Newbie

  • Members
  • Pip
  • 5 posts
umm, how do you call a class that you have made if it is nested in another one? would it be

weapon.longsword


to call up what has been put in to this class


class weapon

{

class longsword

{

public:

int cost,range;

string dmg, dmgtype, size;

cost = 20;

dmg = (rand()%7) +1;

range = 5;

dmgtype = "slashing";

size = "one handed";

};

};



#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
You shall use ::
Here's an example:
#include <iostream>

class C1
{
    public:
        void foo() { std::cout << "C1" << std::endl; }
        
        class C2
        {
            public:
                void foo() { std::cout << "C2" << std::endl; }
        };
};

int main()
{
    C1 c1;
    C1::C2 c2;
    
    c1.foo();
    c2.foo();

    return 0;
}

I think you shall read more about classes. Your code seems very messy, and won't work. Also, instead of these nested classes, have you thought about inheritance?

#3
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Yes, I'm getting £10000*10^9 from my dad when he kicks the bucket.

Sorry, I couldn't resist that one.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums