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

  • SEARCH
  • Home
  • 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 9157177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:57:00+00:00 2026-06-17T12:57:00+00:00

I am learning C++ and CppUnit at the same time, using netbeans 7.2. I

  • 0

I am learning C++ and CppUnit at the same time, using netbeans 7.2.

I create the following file

#include <cstdlib>

using namespace std;

/*
 * 
 */
class Subtract{
public:
    int minus(int a, int b){
        return a-b;
    }
};

int main(int argc, char** argv) {

    return 0;
}

And then I right-click to generate the following cppunit test file

#include "newtestclass.h"


CPPUNIT_TEST_SUITE_REGISTRATION(newtestclass);

newtestclass::newtestclass() {
}

newtestclass::~newtestclass() {
}

void newtestclass::setUp() {
}

void newtestclass::tearDown() {
}

int Subtract::minus(int a, int b);

void newtestclass::testMinus() {
    int a=89;
    int b=55;
    Subtract subtract;
    int result = subtract.minus(a, b);
    CPPUNIT_ASSERT_EQUAL(34,result);
}

When I try to run the test, it gives the following errors

g++    -c -g -I. -MMD -MP -MF build/Debug/GNU-MacOSX/tests/tests/newtestclass.o.d -o build/Debug/GNU-MacOSX/tests/tests/newtestclass.o tests/newtestclass.cpp
tests/newtestclass.cpp:25: error: 'Subtract' has not been declared
tests/newtestclass.cpp: In member function 'void newtestclass::testMinus()':
tests/newtestclass.cpp:30: error: 'Subtract' was not declared in this scope
tests/newtestclass.cpp:30: error: expected `;' before 'subtract'
tests/newtestclass.cpp:31: error: 'subtract' was not declared in this scope
make[1]: *** [build/Debug/GNU-MacOSX/tests/tests/newtestclass.o] Error 1
make: *** [.build-tests-impl] Error 2

How do I get this to work properly?

  • 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-17T12:57:01+00:00Added an answer on June 17, 2026 at 12:57 pm

    In C++, the convention is to declare the classes and functions in a header file (.h file) and implement them in the source file (.cpp file).

    Your Subtract.h file (declarations) should have only this:

    class Subtract {
    public:
        int minus(int a, int b);
    };
    

    Your Subtract.cpp file (implementation) should have this:

    #include "Subtract.h"
    
    int Subtract::minus(int a, int b)
    {
        return a-b;
    }
    

    Then you #include “Subtract.h” in your newtestclass.cpp file.

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

Sidebar

Related Questions

Learning xml, Can anyone help me? I have following XML code: **<book lang=en>name of
Learning sed, I want to change the drive letter of the following input lines
Learning C++ and see the class laid out like this: class CRectangle { int
Learning rails and something smells a little funny. I have the following form for
Learning java newly. Can anybody clear my doubt in following? My demo application has
Learning about Explicit Cursors and trying to create my frst one.: SET SERVEROUTPUT ON
Learning python for the first time and it's I'm reading the JSON and decoding
Learning clojure, trying to create a lazy infinite sequence of all prime numbers. I'm
Recently learning Android, there is a Handler class in android which is very useful.
Learning Java, so be gentle please. Ideally I need to create an array of

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.