Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-15-2008, 04:49 PM
ligerz785 ligerz785 is offline
Newbie
 
Join Date: Apr 2008
Posts: 5
Rep Power: 0
ligerz785 is on a distinguished road
Default calling up classes that are nested in another class

umm, how do you call a class that you have made if it is nested in another one? would it be
Code:
weapon.longsword
to call up what has been put in to this class

Code:
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";
};
};
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-16-2008, 12:39 AM
v0id's Avatar   
v0id v0id is offline
Retired
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,654
Last Blog:
CherryPy(thon)
Rep Power: 29
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default Re: calling up classes that are nested in another class

You shall use ::
Here's an example:
Code:
#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?
__________________
05-03-2007 - 11-13-2008
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-16-2008, 03:34 PM
Xav's Avatar   
Xav Xav is offline
Code Warrior
 
Join Date: Mar 2008
Location: On God's Planet
Posts: 9,897
Last Blog:
Web slideshow in JavaS...
Rep Power: 78
Xav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud ofXav has much to be proud of
Send a message via MSN to Xav
Default Re: calling up classes that are nested in another class

Yes, I'm getting £10000*10^9 from my dad when he kicks the bucket.

Sorry, I couldn't resist that one.
__________________


Mr. Xav | Website | Forums | Blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP 5 and OOP Jordan PHP Tutorials 11 09-22-2008 02:58 AM
Tutorial: Starting C# with C# 2008 Express Edition Jordan CSharp Tutorials 19 08-08-2008 01:48 PM
Understanding the differences between a class and struct in C# : Jordan CSharp Tutorials 4 04-20-2008 10:32 AM
Issue writing to file: pointer to a class which contains pointers to other classes Sheemer C and C++ 0 08-21-2007 02:17 AM


All times are GMT -5. The time now is 11:16 AM.

Contest Stats

WingedPanther ........ 2753.6
Xav ........ 2704
Brandon W ........ 1702.32
John ........ 1207.73
marwex89 ........ 1175.24
morefood2001 ........ 966.05
dcs ........ 655.75
Steve.L ........ 475.59
orjan ........ 418.58
Aereshaa ........ 383.54

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 101%


Complete - Celebrate!

Ads