string array, data member initializer not allowed

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

string array, data member initializer not allowed

Postby demetri90 » Fri Apr 06, 2012 11:56 am

I'm getting a few errors, however I'm not sure what's going on.

Code: Select all
1>------ Build started: Project: Mallous_e5c1, Configuration: Debug Win32 ------
1>Build started 4/6/2012 1:55:15 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\Mallous_e5c1.unsuccessfulbuild".
1>ClCompile:
1>  Mallous_e5c1.cpp
1>c:\users\demetri\documents\visual studio 2010\projects\mallous_e5c1\mallous_e5c1\mallous_e5c1.cpp(19): error C2059: syntax error : '{'
1>c:\users\demetri\documents\visual studio 2010\projects\mallous_e5c1\mallous_e5c1\mallous_e5c1.cpp(19): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\users\demetri\documents\visual studio 2010\projects\mallous_e5c1\mallous_e5c1\mallous_e5c1.cpp(21): error C2864: 'Numbers::hundred' : only static const integral data members can be initialized within a class
1>c:\users\demetri\documents\visual studio 2010\projects\mallous_e5c1\mallous_e5c1\mallous_e5c1.cpp(22): error C2864: 'Numbers::thousand' : only static const integral data members can be initialized within a class
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.04
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========




Code: Select all
/*
This is a class that can translate whole dollar amounts in the range 0 through 9999
into an English description of the number.
***********
Designed by: Demetri Mallous
*/

#include <iostream>
#include <string>
using namespace std;

//class Numbers
class Numbers
{
   //single int member variable
   int number;

   //static string members
   string lessThan20[20] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten",
      "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
   string hundred = "hundred";
   string thousand = "thousand";
};

// main function
int main()
{
   int inputNum;
   cout << "Enter number: ";
   cin >> inputNum;
   cout << "\n";
   
   system("PAUSE");

   return 0;
}
demetri90
 
Posts: 4
Joined: Thu Mar 29, 2012 8:09 pm

Re: string array, data member initializer not allowed

Postby exomo » Sat Apr 07, 2012 11:11 pm

You should add the static keyword to the members that are static.
Who needs a signature anyway.
User avatar
exomo
 
Posts: 879
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden


Return to For Beginners

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 1 guest