Thread: using class constant in another class

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question using class constant in another class

    Hi!

    I'm having problems using class Color in another class called Support.

    This is my code:

    "colors.hpp"

    Code:
     # ifndef COLORS_H
     # define COLORS_H
     
     # include <windows.h>
     
     class Color
     {
     	public:
     		// foreground colors
     		static const FRONT_DARKGREEN = FOREGROUND_GREEN;
     		static const FRONT_DARKRED   = FOREGROUND_RED;
     };
     
     # endif // COLORS_H
    "support.hpp"

    Code:
     # ifndef COLORS_H
     # define COLORS_H
     
     # include "colors.hpp"
     
     class Support
     {
     	public:
     		unsigned short col = FRONT_DARKGREEN;	// this is not working
     };
     
     # endif // COLORS_H
    How can I use FRONT_DARKGREEN constant in my Support class?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Here's a few problems I found:

    1. In your class Color, the variables FRONT_DARKGREEN and FRONT_DARKRED don't have a type.

    2. You're using the same include guards for both files.

    3. The variable col in your Support class is not a constant.

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    It's working now. Thanks!
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inherite nonvirtual class functionality
    By DrSnuggles in forum C++ Programming
    Replies: 2
    Last Post: 04-30-2009, 01:52 PM
  2. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM
  3. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM