How do I fix this?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LilProblems
    New Member
    • Nov 2009
    • 4

    How do I fix this?

    Hi Can someone please help me figure out what I am doing wrong here? I am trying to write the code for a plasma pistol but I have an error that reads
    Error 1 error C2228: left of '.pressTrigger' must have class/struct/union

    I know it is because oldPistol is not a class or struct but how do I fix this without screwing up my whole program? Here is my code that has the problem:

    Code:
    Code:
    #include <iostream>
    using namespace std;
    
    class plasmaPistolClass
    {
    private:  
            int ammo;                       
            int rateOfFire;        
            int destructivePower;   
    public:  
            bool safetyOn;  
            int maxAmmo;   
            void pressTrigger(void);  
            void load(int nmbrOfBolts);  
            void setDestructivePower(int powerSetting);  
            int showDestructivePower(void);  
            void setRateOfFire(int boltsPerTriggerPress);  
            int showRateOfFire(void);   
            int ammoRemaining(void);  
    
     
          plasmaPistolClass();  
         
          plasmaPistolClass(int,int);
    };   
    
    int main()
    {
        plasmaPistolClass oldPistol();
        plasmaPistolClass newPistol(7,75);
    	cout << "Firing Old pistol" << endl;
    	oldPistol.pressTrigger();   //ehis is where the error shows up at
        system("pause");    
        return 0;
    }
    Any help will be greatly appreciated.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    This

    plasmaPistolCla ss oldPistol();

    should be this

    plasmaPistolCla ss oldPistol;

    The way you have the compiler thinks you are declaring a function, oldPistol, returning plasmaPistolCla ss so oldPistol is a function not a variable.

    Comment

    • LilProblems
      New Member
      • Nov 2009
      • 4

      #3
      I fixed that part just to generate a new problem

      int main()
      {
      plasmaPistolCla ss oldPistol;
      plasmaPistolCla ss newPistol(7,75) ;
      cout << "Firing Old pistol" << endl;
      oldPistol.press Trigger;
      system("pause") ;
      return 0;
      The error is this:
      error C3867: 'plasmaPistolCl ass::pressTrigg er': function call missing argument list; use '&plasmaPistolC lass::pressTrig ger' to create a pointer to member

      but we haven't learned anything about pointers yet so I am not sure what to do to fix this,

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        lol, I said

        This

        plasmaPistolCla ss oldPistol();

        should be this

        plasmaPistolCla ss oldPistol;
        not

        This

        oldPistol.press Trigger();

        should be this

        oldPistol.press Trigger;
        The first is instantiation and gets confused as a function declaration with the () the second is a function call and is not valid without the ().

        Only change the thing I said to change.

        Comment

        • LilProblems
          New Member
          • Nov 2009
          • 4

          #5
          Thank you, Banfa. That corrected the problem so that it will compile now but I have a lot more deeper problems than that. The output is way off. Actually most of it does not even show when I run it. So back to the drawing board I go.
          Your help is extremely appreciated.

          Comment

          Working...