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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:35:37+00:00 2026-06-17T20:35:37+00:00

I have a class Color that holds values for the red, green, blue, and

  • 0

I have a class Color that holds values for the red, green, blue, and alpha channels of a color. The class constructor lets you create a new color by specifying values for the four channels. However, for convenience, I would also like to have some “premade” colors available for the programmer. For example instead of having something like

DrawBox(new Color(255, 0, 0));

you would be able to say

DrawRectangle(Color::Red);

Where Color.Red is an instance of Color that lives inside the Color class. How can I declare these instances of Color inside the Color class? I’m sure there’s a name for this technique, but I had no idea what search terms to use when I was looking for help online.

I’m not using any built-in or publicly-available classes or libraries because this is part of a personal exercise in creating a basic graphics stack.

Thanks for your help!

  • 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-17T20:35:38+00:00Added an answer on June 17, 2026 at 8:35 pm

    First of all, avoid using new. You could use Color as simple value-type.

    Now as an answer to your question, yes, you can do that as:

    //color.h
    
    typedef unsigned char byte;
    
    class Color
    {
        public:
            //declaration
            const static Color Red;
            const static Color Green;
            const static Color Blue;
        public:
    
           Color(byte red, byte green, byte blue);
    };
    
    //define the static members in color.cpp file
    #include "color.h"
    
    const Color Color::Red(255,0,0);
    const Color Color::Green(0,255,0);
    const Color Color::Blue(0,0,255);
    

    Then use Color::Red as you want to use.

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

Sidebar

Related Questions

Possible Duplicate: Difference between Color.red and Color.RED I have seen that the Java class
I am tracking three color points - red, green and blue. I have currentFrames
I have an IValueConverter class that is used to change the background color of
Let's say I have a PHP class called Color , it's constructor accepts various
I have a class with a variable that supposed to hold a color that
I have a class Unit that holds functions and variables that all Units in
I have 2 css classes that hold the background-color property. One class is for
We have a color animation that blends from red to white. Currently, this is
I have that Class : public Class Color { public virtual int Id {
Say I have a class named testThing: .testThing { background-color:#000000; float:left; height:50px; width:50px; }

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.