CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2016
    Posts
    9

    Class Constructor

    Is my code correct for the following question?

    Write the interface (.h file) of a class Counter containing: * A data member counter of type int . * A constructor that accepts no arguments . * A function called increment that accepts no parameters and returns no value . * A function called getValue that accepts no parameters . Write the interface (.h file) of a class Counter containing:
    •A data member counter of type int .
    •A constructor that accepts no arguments .
    •A function called increment that accepts no parameters and returns no value .
    •A function called getValue that accepts no parameters .

    Code:
    #ifndef COUNTER_H
    #define COUNTER_H
    
    class Counter
    {
    	private:
    		int counter;
    	public:
    		Counter();	
    		void increment();
    		int getValue();
    };
    	
    Counter::Counter(){
    }
     
    void Counter::increment(){
    }
    
    int Counter::getValue(){
    }
    
    #endif

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Class Constructor

    I don't think so. It just asks for the interface, which I would assume means the class definition. You've written some impartial implementations following the class definition. It doesn't look like you need them for the assignment, but if you're going to write them, they should work.

  3. #3
    Join Date
    Oct 2016
    Posts
    9

    Re: Class Constructor

    Thanks for your help, I got the code to work. I needed to separate the code into a .h file and a .cpp file.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured