943,523 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3515
  • C++ RSS
Jul 25th, 2004
0

Error C2734: 'Value' : const obje

Expand Post »
I'm new to C++ and I'm studying out of a book (Game Programming - All In One, 2002) From what I've seen from other programs it's sort of out of date. Can someone tel me what's wrong with this?

-Error C2734: 'Value' : const object must be initialized if not extern


(It origionaly used std::cout and std::cin)

#include <iostream>
using namespace std;



main (void)
{
const float Value, FeetPerMeter = Value;
float Length1;
float Length2;
float Length3;

cout << "Enter the first lenght in meters: ";
cin >> Length1;
cout << "Enter the second length in meters: ";
cin >> Length2;
cout << "Enter the third lenght in meters: ";
cin >> Length3;

cout << "First length in feet is: " << Length1 * FeetPerMeter << endl;
cout << "Second length in feet is: " << Length2 * FeetPerMeter << endl;
cout << "Third length in feet is: " << Length3 * FeetPerMeter << endl;

return 0;
}

This is what the book told me to insert, but it even looks incorrect to me. HMM, does anyone know what's wrong with this?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
.·)Tusky(·. is offline Offline
8 posts
since Jul 2004
Jul 25th, 2004
0

Re: Error C2734: 'Value' : const obje

Well, I put in a number and then it worked not as i planed although. First i enterd the first, then the second, then the third. Then it just shuts the window concole.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
.·)Tusky(·. is offline Offline
8 posts
since Jul 2004
Jul 25th, 2004
0

Re: Error C2734: 'Value' : const obje

Quote originally posted by .·)Tusky(·. ...
Well, I put in a number and then it worked not as i planed although.
In the code you posted, Value does not have a value (as the error message tried to tell you).

Quote originally posted by .·)Tusky(·. ...
First i enterd the first, then the second, then the third. Then it just shuts the window concole.
It sounds like an issue with the environment you are running it out of. Perhaps if you ran your program from a command line it would work as expected. But you may find a remedy by adding this line right before the 'return 0;' of main.
C++ Syntax (Toggle Plain Text)
  1. cin.get();
Explanation. Cure.
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Jul 26th, 2004
0

Re: Error C2734: 'Value' : const obje

Don't use const(ant) float.Try using a normal float .
Once a constant is initialised it's value cant be changed AND you have to initialise a constant ALWAYS.

const float num = 10;
const float num1 = num;

The above will work. :!:
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Unary Operators
Next Thread in C++ Forum Timeline: Devanagari Keyboard Program





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC