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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:26:10+00:00 2026-05-14T15:26:10+00:00

I am teaching myself to write classes in C++ but can’t seem to get

  • 0

I am teaching myself to write classes in C++ but can’t seem to get the compilation to go through. If you can help me figure out not just how, but why, it would be greatly appreciated. Thank you in advance! Here are my three files:

make_pmt.C

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

using namespace std;


int main() {
    CPMT *pmt = new CPMT;
    pmt->SetVoltage(900);
    pmt->SetGain(2e6);

    double voltage = pmt->GetVoltage();
    double gain= pmt->GetGain();

    cout << "The voltage is " << voltage
         << " and the gain is " << gain << "." <<endl;

    return 0;
}

pmt.C

#include "pmt.h"

using namespace std;

class CPMT {
    double gain, voltage;
    public:
        double GetGain() {return gain;}
        double GetVoltage() {return voltage;}

        void SetGain(double g) {gain=g;}
        void SetVoltage(double v) {voltage=v;}
};

pmt.h

#ifndef PMT_H
#define PMT_H 1

using namespace std;

class CPMT {
    double gain, voltage;
    public:
        double GetGain();
        double GetVoltage();

        void SetGain(double g);
        void SetVoltage(double v);
};

#endif

And for reference, I get a linker error (right?):

Undefined symbols:
  "CPMT::GetVoltage()", referenced from:
      _main in ccoYuMbH.o
  "CPMT::GetGain()", referenced from:
      _main in ccoYuMbH.o
  "CPMT::SetVoltage(double)", referenced from:
      _main in ccoYuMbH.o
  "CPMT::SetGain(double)", referenced from:
      _main in ccoYuMbH.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
  • 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-05-14T15:26:10+00:00Added an answer on May 14, 2026 at 3:26 pm

    First some taxonomy.
    This

    class CPMT {
        public:
            double GetGain();
            // ...
    };
    

    is defining a class without also defining the member functions. This

    class CPMT {
        public:
            double GetGain() {return gain;}
            // ...
    };
    

    is defining the same class, with also defining its member functions (implicitly) inline. This

    double CPMT::GetGain() {return gain;}
    // ...
    

    is defining the member functions (not inline).

    Now, if you want to separate implementation from interface, your header needs to define the class, while your implementation file needs to define its member functions. So the pure class definition

    class CPMT {
        public:
            double GetGain();
            //...
    };
    

    goes into the header file and the implementation

    double CPMT::GetGain() {return gain;}
    // ...
    

    goes into the implementation file – except for those member functions you want to implement inline. Since inline asks the compiler to substitute a function’s implementation for every call to it, the implementation must be present where the function is called. That’s why the implementations of inlined functions must be in header files.

    There are two ways to inline a member function. One is to define it within its class’s definition

    class CPMT {
        public:
            double GetGain() {return gain;}
            // ...
    };
    

    which implicitly makes it inline. The other is to explicitly inline it

    class CPMT {
        public:
            double GetGain();
            //...
    };
    
    inline double CPMT::GetGain() {return gain;}
    // ...
    

    In both cases the implementation must be in the header file.

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

Sidebar

Related Questions

I'm teaching myself Python and my most recent lesson was that Python is not
I am teaching myself Haskell. I want to write a function that recursively finds
I'm slowly teaching myself cocoa for the iPhone(through the Stanford Class on iTunes U
So I'm teaching myself Python, and I'm having an issue with lists. I want
I've been teaching myself Objective-C over the past month or so (I'm a Java
I am currently teaching myself about various data strutures and am a little frustrated
I'm teaching myself some basic scraping and I've found that sometimes the URL's that
So I'm teaching myself Ruby on Rails, with a PHP background. I've written a
I'm teaching myself Objective-C from a book ( Cocoa programming for mac OS X
I was recently teaching myself Python and discovered the LBYL/EAFP idioms with regards to

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.