Thread: Simple C++ Compilation Question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Registered User
    Join Date
    Nov 2005
    Posts
    88
    I changed the definition to indiciate that the constant should be externally linked. I did this by using the extern const strTest = "Test" in main.cpp. The project compiles correctly. However, when I assign strTest to a static member variable of a class (the static member definition occurs in the .cpp file), it fails to assign the data "Test" to the variable. I put a break point on the assignment line to discover the data contained by strTest is believed to be "". If I place the definition in the .h file, removing the extern, this issue does not occur. However, I want the definition to exist in the cpp file. Is there any reason strTest would be "" despite the constant definition assigning "Test" to it?

    Edit: Further testing by placing a breakpoint at the line of code that assigns "Test" to strTest occurs AFTER the static member variable assignment. Why is this the case? Aren't const assignments suppposed to have precedence?

    Thank you.
    Last edited by mercury529; 07-28-2006 at 02:47 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple question regarding variables
    By Flakster in forum C++ Programming
    Replies: 10
    Last Post: 05-18-2005, 08:10 PM
  2. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  3. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 09:46 AM
  4. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 12:15 PM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 06:58 PM