Error C2734: 'Value' : const obje

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jul 2004
Posts: 8
Reputation: .·)Tusky(·. is an unknown quantity at this point 
Solved Threads: 0
.·)Tusky(·.'s Avatar
.·)Tusky(·. .·)Tusky(·. is offline Offline
Newbie Poster

Error C2734: 'Value' : const obje

 
0
  #1
Jul 25th, 2004
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?

"But I'm not a slave to a god that doesn't exist
But I'm not a slave to world that doesn't give a S•••" - Marilyn Manson (The Fight Song)
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 8
Reputation: .·)Tusky(·. is an unknown quantity at this point 
Solved Threads: 0
.·)Tusky(·.'s Avatar
.·)Tusky(·. .·)Tusky(·. is offline Offline
Newbie Poster

Re: Error C2734: 'Value' : const obje

 
0
  #2
Jul 25th, 2004
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.

"But I'm not a slave to a god that doesn't exist
But I'm not a slave to world that doesn't give a S•••" - Marilyn Manson (The Fight Song)
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,362
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 241
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Error C2734: 'Value' : const obje

 
0
  #3
Jul 25th, 2004
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).

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.
  1. cin.get();
Explanation. Cure.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: Error C2734: 'Value' : const obje

 
0
  #4
Jul 26th, 2004
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. :!:
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC