Thread: Classes issue

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    3

    Classes issue

    Ok, so i know that:

    A: there's going to be some uber-simple answer to this that makes me feel like an idiot.
    or
    B: someone else already made a thread about this issue.

    Code:
    class Weapons{
    public:
    		int wClub;
    };
    Code:
    case 13462:
    	system("cls");
    	cout << "You now have a wooden club, if you already had one, way to waste time.\n\n";
    	Weapons.wClub = 1;
    	system("pause");
    	break;
    I keep getting the error message "expected primary-expression before '.' token" linked specifically to the line:
    Code:
    Weapons.wClub = 1;
    What's my issue?

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Weapons is a class and not an instance of a class. You either need to first create an instance of that class and then assign 1 to the wClub member of that specific instance or you'd need to make the variable static in which case you could do the assignment as written. I'm guessing you want the former and not the latter.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Weapons MyWeapon;
    MyWeapon.wClub = 1;
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    Ah, thanks. I had a feeling it would be really simple.

  5. #5
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    case 13462:
    ?? this is a very magical number...i suggest you declare things like this as const so you can refer to it in a meaningful way in your code like

    case: W_CLUB

  6. #6
    Registered User
    Join Date
    Mar 2010
    Posts
    3
    Quote Originally Posted by rogster001 View Post
    ?? this is a very magical number...i suggest you declare things like this as const so you can refer to it in a meaningful way in your code like

    case: W_CLUB
    Haha, yea, that's probably a good idea.

    The reason that it's such a screwed up number is because i'm trying to make an option to input cheat codes for an rpg i'm attempting to make, and making it easy to guess would just be silly.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with abstract classes
    By DavidP in forum C# Programming
    Replies: 1
    Last Post: 08-18-2008, 03:03 PM
  2. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  3. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  5. include question
    By Wanted420 in forum C++ Programming
    Replies: 8
    Last Post: 10-17-2003, 03:49 AM