Link to home
Start Free TrialLog in
Avatar of CBIZCBAS
CBIZCBAS

asked on

Declare array in header file

I'm trying to declare an array for a graph problem in class.  When I try and print the arrays I get an "expression must have class type" error.

#pragma once
#ifndef GRAPH_H
#define GRAPH_H
#include <list>
#include <vector>
#include <string>
#include <set>

class Graph {
private:
	static const int MAXIMUM = 20;
	int mileageGraph[MAXIMUM][MAXIMUM];  //compiles so long as I comment out my print function
	int costGraph[MAXIMUM][MAXIMUM];
	std::vector<std::string> vertex;
	//int labels[MAXIMUM];
	int manyVertices;

public:  //this is where the functions go

	Graph();
	void addVertex(const std::string value);
	int getMileage(int source, int destination);
	int getCost(int source, int destination);
	void addEdge(int source, int destination, int mileage, int cost);
	bool isEdge(int source, int destination) const;
	//void shortestPath(int source);
	int getID(std::string vertex);
	std::string getName(int vertexId);
	int size();
	void printDirectFlights();
};

#endif // !GRAPH_H

void Graph::printDirectFlights()
{
	cout << "Direct Flights" << endl;
	cout << left <<
		setw(10) << "Source" <<
		setw(15) << "Destination" <<
		setw(10) << "Mileage" <<
		setw(10) << "Price" << '\n';
	for (int i = 1; i < MAXIMUM; i++)
	{
		for (int j = 1; j < MAXIMUM; j++)
		{
			if (costGraph.isEdge(i, j))  //breaks
			{
				cout << left <<
					setw(10) << getName(i) <<
					setw(15) << getName(j) <<
					setw(10) << mileageGraph.getMileage(i, j) <<  //breaks
					setw(10) << costGraph.getCost(i, j) << '\n';  //breaks
			}
		}
	}
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CBIZCBAS
CBIZCBAS

ASKER

I have fought with this all day, bless you
:)

Sometimes those little things get stuck in your head and just won't leave without help.

Glad you're going again!!!