Gå til innhold

[LØST] C++ problemer med struct


Anbefalte innlegg

Hallo

 

Jeg har laget en data structure Point som holder styr på koordinatene til et punkt under ett navn. Jeg har fått til å printe ut disse koordinatene når jeg kjører alt i Main, men jeg sliter litt med å få brukt denne i en sepparat header-fil. Kunne dere hjulpet meg litt? Feilen jeg får ligger i header-fila på linje 11:

error: 'Point' has not been declared

 

main.cpp

 

 

#include <iostream>
using namespace std;
#include "coordinates.h"
/*A data structure is a group of data elements grouped together under one name*/
struct Point
{
char Letter;
int x;
int y;
int z;
}point1, point2;

void coordinates ();
void printCoordinates (Point myPoints);

int main()
//Source: http://www.functionx.com/cpp/Lesson24.htm
{
// Point1 location;
point1.Letter = 'A';
point1.x	  =  1;
point1.y	  =  2;
point1.z	  =  3;

// Point2 location;
point2.Letter = 'B';
point2.x	  =  2;
point2.y	  =  4;
point2.z	  =  6;
Coordinates bo;
bo.coordiCrap();
printCoordinates(point1);
printCoordinates(point2);
return 0;
}

//The one bellow is working when set in Main.
/*void printCoordinates (Point myPoints)
{
cout << "Point Location " << myPoints.Letter << " ("
	 << myPoints.x << ", " << myPoints.y << ", " << myPoints.z << ");" << endl;
}
*/

 

 

coordinates.h

 

 

#ifndef COORDINATES_H
#define COORDINATES_H

class Coordinates
{
public:
	Coordinates();
	coordiCrap(Point myPoints);
protected:
private:
};
#endif // COORDINATES_H

 

 

 

Coordinates.cpp

 

 

#include "coordinates.h"
#include <iostream>
using namespace std;

Coordinates::Coordinates()
{
cout << "I am a Coordinate" << endl;
}
Coordinates::coordiCrap(Point myPoints)
{
cout << "did you say cola?" << endl;
cout << "Point Location " << myPoints.Letter << " ("
	 << myPoints.x << ", " << myPoints.y << ", " << myPoints.z << ");" << endl;
}

 

 

Lenke til kommentar
Videoannonse
Annonse

*kremt* bare glem det. Fikk hjelp av en venn. =)

 

#include <iostream>
using namespace std;
#include "coordinates.h"
void coordinates ();
void printCoordinates (Point myPoints);
int main()
//Source: http://www.functionx.com/cpp/Lesson24.htm
{
   Point point1;
   Point point2;
   point1.Letter = 'A';
   point1.x	  =  1;
   point1.y	  =  2;
   point1.z	  =  3;
   // Point2 location;
   point2.Letter = 'B';
   point2.x	  =  2;
   point2.y	  =  4;
   point2.z	  =  6;
   Coordinates bo;
   bo.coordiCrap(point1);
return 0;
}

#ifndef COORDINATES_H
#define COORDINATES_H
/*A data structure is a group of data elements grouped together under one name*/
struct Point
{
   char Letter;
   int x;
   int y;
   int z;
};
class Coordinates
{
   public:
    Coordinates();
    void coordiCrap(Point myPoints);
   protected:
   private:
};
#endif // COORDINATES_H

 

#include "coordinates.h"
#include <iostream>
using namespace std;

Coordinates::Coordinates()
{
   cout << "I am a Coordinate" << endl;
}
void Coordinates::coordiCrap(Point myPoints)
{
   cout << "did you say oaoeuaoeu" << endl;
   cout << "Point Location " << myPoints.Letter << " ("
	 << myPoints.x << ", " << myPoints.y << ", " << myPoints.z << ");" << endl;
}

Endret av r2d290 waits for Obi-Wan
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...