I'm trying to create class/header for my program which should calculate distanaces between cities declared by array "use" plus arrays of there coordinates as you see in code below

// file line.h

#ifndef LINE_H
#define LINE_H
const int cities = 6;

class Line
{
 private:
  string use[] = {"Phoenix", "Baton Rouge", "Bismark", "Columbia", "Olympia", "Springfield"};     //predefined parameters name of cities
  int x[] = {380, 890, 650, 1140, 70, 920};                                                         // x coordinate of each city
  int y[] = {280, 180, 690, 300, 700, 470};                                                         // y coordinate of each city

  string dest[] = {"Phoenix"};                   //cities which been used in calculation, as a target city and starting city
  int dist[];                                    //calculated distanced between cities

  int possition[] = {0, 1, 2, 3, 4, 5};          //to be use for swap function, after swaping to find city with shortest distatce from start city
  int calc[];                                    //array to hold temporary distances
  int x1;
  int x2;
  int y1;
  int y2;

 public:
  Line();
  void calculate();
  void find();
  bool notInDest();
  void sort();
  void swap();
  void smallest();
  void display();
};

#endif;

I created prototypes of functions in cc program and tryed to compile, but got this error messages

line.h:10: syntax error before `['
line.h:10: missing ';' before right brace
line.h:14: syntax error before `['
line.h:24: parse error before `public'
line.h:33: parse error before `}'
line.cc:6: definition of implicitly-declared `Line::Line()'
line.cc:6: declaration of `Line::Line()' outside of class is not definition
line.cc:9: no `void Line::find()' member function declared in class `Line'
line.cc:12: parse error before `bool'
line.cc:16: parse error before `void'
line.cc:20: parse error before `void'
line.cc:24: parse error before `void'
line.h:15: storage size of `dist' isn't known
line.h:18: storage size of `calc' isn't known

My main concern is the declaration of string use and dest. Can you please explain me what I did wrong?

1) You need to include <string> because you try to use the string class.
2) You need to qualify each use of string with std::.
3) You can't initialize arrays in a class declaration.
4) Because of 3, you must supply a size for the arrays.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.