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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:50:27+00:00 2026-06-18T23:50:27+00:00

class_one.h : #ifndef CLASS_ONE #define CLASS_ONE #include <string> namespace ones{ typedef enum{BLACK, WHITE, RED}

  • 0

class_one.h:

#ifndef CLASS_ONE
#define CLASS_ONE
#include <string>

namespace ones{

    typedef enum{BLACK, WHITE, RED} b_color;

    typedef char b_letter;
    const b_letter letters[4] = {'A', 'B', 'C', 'D'};

    class one{
        b_color color;
        b_letter letter;
        public:
        one(b_color, b_letter);
        std::string combo();
        b_color getColor();
        b_letter getLetter();
    };
}
#endif

Given this header file, how should I go about creating the .cpp file, and how then instantiate this class in another file, main.cpp?
I would think something like this:

class_one.cpp

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

using namespace ones;

class one
{
    b_color color;
    b_letter letter;
public:

    one(b_color c, b_letter l) //Not sure about this one..
    {
        color = c;
        letter = l;
    }
    std::string combo()
    {
        return "blahblah temporary. letter: " + letter; //not finished
    }
    b_color getColor()
    {
        return color;
    }
    b_letter getLetter()
    {
        return letter;
    }
};

and then to instantiate it, I would do something like this:

main.cpp

#include "class_one.h"

int main()
{
    ones::one test(ones::BLACK, ones::letters[0]);
    //cout<<test.name()<<endl;
    return 0;
}

Everything is extracted from a larger cluster of files, but this is the essentials of my question.. The header file should be correct, but I’m not sure how to instantiate the ‘one’ class, and not with that constructor. I think the constructor I defined in the .cpp is wrong. I’m used to Java, so I’ve never seen a constructor like the one in the header file, if it’s even a constructor. To me it looks like method(int, int) instead of what I’m used to: method(int a, int b)
When running this I get this error:

main.obj : error LNK2019: unresolved external symbol "public: __thiscall ones::one::one(enum ones::b_color, char)" (??0one@ones@@QAE@W4b_color@1@D@Z) referenced in function _main
<path>/project.exe : fatal error LNK1120: 1 unresolved externals

Sorry for the incredibly stupid naming I have here, but it does make sense for the purpose. May be some typing errors in the question codes as I’ve written most of this by hand right now.
Any help appreciated..

  • 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-18T23:50:28+00:00Added an answer on June 18, 2026 at 11:50 pm

    Your cpp file should look like this:

    #include "class_one.h"
    
    ones::one::one(ones::one::b_color c, ones::one::b_color l)
    {
        //code here
    }
    
    std::string ones::one::combo()
    {
       // code here
    }
    
    // additional functions...
    

    And so on. You don’t redefine the class with a class block, you just specify the individual function definitions like I showed here. The function definition format should be something like this:

    [return type] [namespace]::[class]::[function]([parameters])
    {
        // code here
    }
    

    It looks like you’re good on instantiation. You also don’t have to redeclare the member variables.

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

Sidebar

Related Questions

When I run the following code... #ifndef KEYEDITEM_H_INCLUDED #define KEYEDITEM_H_INCLUDED #include <string> typedef std::string
#ifndef IMAGEDATA_H #define IMAGEDATA_H #include <iostream> #include <vector> class ImageData { public: std::string foo;
#include <iostream> #include <string.h> #include <iomanip> #include <cstring> #include <cassert> using namespace std; #ifndef
I have this a class called PPString: PPString.h #ifndef __CPP_PPString #define __CPP_PPString #include "PPObject.h"
I'm getting a compiler error with this header file: #ifndef GAME1_H #define GAME1_H #include
#ifndef CLASS_VEHICLE_ #define CLASS_VEHICLE_ #include ns3/ptr.h #include ns3/object.h #include ns3/vector.h #include ns3/core-module.h #include ns3/network-module.h
There is some class wComplex with == operator. #ifndef WCOMPLEX_H #define WCOMPLEX_H #include <stdio.h>
I am trying to use following pattern. #ifndef TRACER_H #include Tracer.h #endif This is
I follow your suggests by now I have another problem. ifndef MARKERCONTAINE_H define MARKERCONTAINE_H
In one class I have a library project with a file class1 with namespace

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.