using class constant in another class

This is a discussion on using class constant in another class within the C++ Programming forums, part of the General Programming Boards category; Hi! I'm having problems using class Color in another class called Support. This is my code: "colors.hpp" Code: # ifndef ...

  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, 04:01 PM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 01:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21