dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [RESOLVED] Burnt out. Not sure what I'm doing wrong

  1. #1
    Join Date
    Nov 2018
    Posts
    7

    [RESOLVED] Burnt out. Not sure what I'm doing wrong

    Code:
    Counter
    {
        int counter;
        int counterID;
        int nCounters;
        Counter(int preset);
        void increment();
        void decrement();
        int getValue();
        int getCounterID();
    };
    int Counter::nCounters = 0;
    Counter::Counter(int value)
    {
        counter = value;
        nCounters = nCounters + 1;
        counterID = nCounters;
    }
    void Counter::increment()
    {
        counter++;
    }
    void Counter::decrement()
    {
        counter--;
    }
    int Counter::getValue()
    {
        return counter;
    }
    int Counter::getCounterID()
    {
        return counterID;
    }
    Name:  Screen Shot 2018-12-07 at 2.32.57 AM.jpg
Views: 86
Size:  20.7 KB
    Last edited by 2kaud; December 7th, 2018 at 09:12 AM. Reason: Fixed code tags

  2. #2
    Join Date
    Nov 2018
    Posts
    4

    Re: Burnt out. Not sure what I'm doing wrong

    It looks like you forgot to say 'struct' or 'class'.

    If you choose 'class', then you need to make your member functions public.

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,515

    Re: Burnt out. Not sure what I'm doing wrong

    Code:
    int Counter::nCounters = 0;
    ... and ncounters static!
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.9.4)

  4. #4
    Join Date
    Nov 2018
    Posts
    7

    Re: Burnt out. Not sure what I'm doing wrong

    Thank you! I figured it out!
    Code:
    int Counter::nCounters = 0;
    
    
    Counter::Counter(int i)
    {
    counter = i;
    
    nCounters++;
    counterID = nCounters;
    }
    
    void Counter::increment()
    {
    counter++;
    
    }
    
    int Counter::getValue()
    {
    return counter;
    }
    void Counter::decrement()
    {
    counter--;
    }
    int Counter::getCounterID()
    {
    return counterID;
    }
    Last edited by 2kaud; December 7th, 2018 at 11:18 AM. Reason: Fixed code tags

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)