Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8310973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:39:14+00:00 2026-06-08T19:39:14+00:00

Recently I’ve been learning how to create methods within classes so that I only

  • 0

Recently I’ve been learning how to create methods within classes so that I only have to write a method once and for each of that class I instantiate I can call the one method and it will work only on the variables of the object that called it, I know how to do this when only using main.cpp and no headers however I am confused on how I should be writing this when I use a class header and cpp.
I have a sample of code similar to what I want to achieve:

#include <iostream>

using namespace::std;

class Object
{
public:
    int stuff;
    void manageStuff();
    Object();
};
void Object::manageStuff()
{
    stuff++;
}

Object::Object() : stuff(0) {}

Object object1, object2;

int main() {
  for (int i = 0; i < 10; i++)
  {
      object1.manageStuff();
      object2.manageStuff();
      cout << object1.stuff << "\n";
      cout << object2.stuff << "\n";
  }
}  

This works fine and allows me to have two instances of Object and a method that works independently for each instance, this is my current project:
main.cpp:

#include <iostream>
#include "Test.h"

using namespace std;

int main()
{

    Test test;

    for (int i = 0; i < 10; i++)
    {
        test.count(); // Here's my error "undefined reference to Test::count"
    }

    return 0;
}  

Test.cpp

#include <iostream>
#include "Test.h"

using namespace std;

Test::Test()
{
    //ctor
}

Test::~Test()
{
    //dtor
}  

Test.h

#include <iostream>

#ifndef TEST_H
#define TEST_H


class Test
{
    public:
        Test();
        virtual ~Test();
        void count();
        int counter();
};

#endif // TEST_H  

and finally TestFunctions.h

#include <iostream>
#include "Test.h"

#ifndef TESTFUNCTIONS_H_INCLUDED
#define TESTFUNCTIONS_H_INCLUDED

void Test::count()
{
    Test::counter++;
    std::cout << Test::counter;
}

#endif // TESTFUNCTIONS_H_INCLUDED  

I’m sure that there will be something that’s very obviously wrong to a more seasoned programmer and I’m about to look a bit thick but any help would be greatly appreciated
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:39:16+00:00Added an answer on June 8, 2026 at 7:39 pm

    I would suggest getting rid of TestFunctions.h, and adding the implementation of Test::count() to Test.cpp. Currently, the TestFunctions.h header is not included anywhere, so you have no access to the definition from main.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I have been told that static class/methods are evil. Take for example my
recently I have been trying to add a link that allows people to delete
Recently I have been dealing with windows LogonUser API. The LogonUser api returns different
Recently I noticed (after others have extended the project) that the compile time significantly
Recently I have been investigating the possibilities of caching in ASP.NET. I rolled my
Recently I've been trying to upgrade this application that I'm working on from JSF
Recently I was able to create a tablet software for my Cerebral Palsy girl
Recently, I was writing a class in which I discovered that I could reduce
Recently I have released my app into the US AppStore. Now I Planed for
Recently I'm doing some work on RTMP streaming, that is using Flowplayer to integrate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.