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 8829959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:57:21+00:00 2026-06-14T07:57:21+00:00

This is the error I am keep getting . undefined reference to my class.

  • 0

This is the error I am keep getting . undefined reference to my class. I am not sure. I think I m linking them. this is how my main looks like.

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

    using namespace std;

     int main()
      {
        randomNumberMagnifier r1, r2;

      cout << "Random Number "<< r1.getRandomNumber();
       cout << endl;


      } 

I am not sure what I am doing wrong.
this is what it looks like. when I compile

      [singha1@cs1 p4]$ g++ -c randomNumberMagnifier.cpp
       [singha1@cs1 p4]$ g++ -o p4Driver.cpp
        g++: no input files
        p4Driver.cpp:(.text+0x8c): undefined reference to `randomNumberMagnifier::getRandomNumber
     collect2: ld returned 1 exit status



      #ifndef RANDOMNUMBERMAGNIFIER_H
#define RANDOMNUMBERMAGNIFIER_H

class randomNumberMagnifier
{
  int addFactor;
  int multFactor;
  bool addOn;
  bool multOn;
  int randomNumber;
  static const int MAX_ADD_FACTOR = 100;
  static const int MAX_MULT_FACTOR = 20;
  static const int MAX_RANDOM = 200;

 public:
  randomNumberMagnifier();

  //~randomNumberMagnifer();

  randomNumberMagnifier& operator=(const randomNumberMagnifier& rhs);

  randomNumberMagnifier(const randomNumberMagnifier& arandom);

  randomNumberMagnifier(bool aState, bool mState);

  int randomMagnifier();

  int getAdd();
  int getMult();

  bool getAddState();
  bool getMultState();

  int getRandomNumber();


};
#endif
  • 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-14T07:57:22+00:00Added an answer on June 14, 2026 at 7:57 am

    you need to provide randomNumberMagnifier.o to g++ command, so it can find function definition. I tested with below command and i worked

    g++ -o p4Driver p4Driver.cpp randomNumberMagnifier.o
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having this annoying error. I keep getting undefined reference to class::method This is the
I keep getting an Notice: Undefined index: did error with this query, and I'm
I keep getting a error:undefined message when calling this AJAX method. $.ajax({ type: GET,
I keep getting this error in Firebug: d is undefined [Break On This Error]
Hi I keep getting this error, I'm trying to get tweets from twitter via
I keep getting this error and have no idea why. I googled and scanned
I keep getting this error on emulator: I copied this from a tutorial and
I keep getting this error Error in readPNG(destfile) : libpng error: PLTE: CRC error
I keep getting this error with my Play 2.0 application: play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[MatchError:
I keep getting this error when using django templates in Google App Engine: TemplateSyntaxError:

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.