[ TechnoChronox @ 05.10.2005. 18:37 ] @
imam problem sa jednim jednostavnim programom... Uglavnom program se sastoji od headera u kojem su deklarisane klase i od glavnog cpp source code filea:

rect.hpp

Code:
#include <iostream.h>

//rect.hpp
class Point
  {
  public:
  void setX(int x) {itsX = x;}
  void setY(int y) {itsY = y;}
  int getX() const {return itsX;}
  int getY() const {return itsY;}
  private:
  int itsX;
  int itsY;
  };

//klasa rectangle pocetak...
class Rectangle
  {
  public:
  Rectangle (int top, int left, int right, int bottom);
  ~Rectangle() {}

  int getTop() const {return itsTop;}
  int getLeft() const {return itsLeft;}
  int getRight() const {return itsRight;}
  int getBottom() const {return itsBottom;}

  Point getUpperLeft() const {return itsUpperLeft;}
  Point getLowerLeft() const {return itsLowerLeft;}
  Point getUpperRight() const {return itsUpperRight;}
  Point getLowerRight() const {return itsLowerRight;}

  void setUpperLeft(Point location) {itsUpperLeft = location;}
  void setLowerLeft(Point location) {itsLowerLeft = location;}
  void setUpperRight(Point location) {itsUpperRight = location;}
  void setLowerRight(Point location) {itsLowerRight = location;}

  void setTop(int top) {itsTop = top;}
  void setLeft(int left) {itsLeft = left;}
  void setRight(int right) {itsRight = right;}
  void setBottom(int bottom) {itsBottom = bottom;}

  int getArea() const;

  private:
  int itsTop;
  int itsLeft;
  int itsRight;
  int itsBottom;
  int itsUpperLeft;
  int itsLowerLeft;
  int itsUpperRight;
  int itsLowerRight;
  };

//kraj rect.hpp


rect.cpp

Code:
#include <iostream.h>
#include <stdlib.h>
#include <rect.hpp>

//pocetak rect.cpp

Rectangle::Rectangle (int top, int left, int right, int bottom)
   {
   itsTop = top;
   itsLeft = left;
   itsRight = right;
   itsBottom = bottom;

   itsUpperLeft.setX(left);
   itsUpperLeft.setY(top);

   itsUpperRight.setX(right);
   itsUpperRight.setY(top);

   itsLowerLeft.setX(left);
   itsLowerLeft.setY(bottom);

   itsLowerRight.setX(right);
   itsLowerRight.setY(bottom);
   }

int Rectangle::getArea() const
  {
  int width = itsRight - itsLeft;
  int height = itsTop - itsBottom;
  return (width*height);
  }


int main()
{
Rectangle myRectangle ( 100, 20, 50 ,80 );


int Area = myRectangle.getArea();

cout << "Area : " << Area << "\n";
cout << "Gornja lijeva x koordinata : " << myRectangle.getUpperLeft().getX() ;
return 0;
system("pause");
}


Radim u devc++ kompajleru i izbaciva mi slijedece greske:


In file included from g:\c__tes~1\weekon~1\rect.cpp:3:
C:\DEV-C_~1\Include\rect.hpp: In method `class Point Rectangle::getUpperLeft() const':
C:\DEV-C_~1\Include\rect.hpp:28: conversion from `const int' to non-scalar type `Point' requested
C:\DEV-C_~1\Include\rect.hpp: In method `class Point Rectangle::getLowerLeft() const':
C:\DEV-C_~1\Include\rect.hpp:29: conversion from `const int' to non-scalar type `Point' requested
C:\DEV-C_~1\Include\rect.hpp: In method `class Point Rectangle::getUpperRight() const':
C:\DEV-C_~1\Include\rect.hpp:30: conversion from `const int' to non-scalar type `Point' requested
C:\DEV-C_~1\Include\rect.hpp: In method `class Point Rectangle::getLowerRight() const':
C:\DEV-C_~1\Include\rect.hpp:31: conversion from `const int' to non-scalar type `Point' requested
C:\DEV-C_~1\Include\rect.hpp: In method `void Rectangle::setUpperLeft(Point)':
C:\DEV-C_~1\Include\rect.hpp:33: `class Point' used where a `int' was expected
C:\DEV-C_~1\Include\rect.hpp: In method `void Rectangle::setLowerLeft(Point)':
C:\DEV-C_~1\Include\rect.hpp:34: `class Point' used where a `int' was expected
C:\DEV-C_~1\Include\rect.hpp: In method `void Rectangle::setUpperRight(Point)':
C:\DEV-C_~1\Include\rect.hpp:35: `class Point' used where a `int' was expected
C:\DEV-C_~1\Include\rect.hpp: In method `void Rectangle::setLowerRight(Point)':
C:\DEV-C_~1\Include\rect.hpp:36: `class Point' used where a `int' was expected
g:\c__tes~1\weekon~1\rect.cpp: In method `Rectangle::Rectangle(int, int, int, int)':
g:\c__tes~1\weekon~1\rect.cpp:14: request for member `setX' in `Rectangle::itsUpperLeft', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:15: request for member `setY' in `Rectangle::itsUpperLeft', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:17: request for member `setX' in `Rectangle::itsUpperRight', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:18: request for member `setY' in `Rectangle::itsUpperRight', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:20: request for member `setX' in `Rectangle::itsLowerLeft', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:21: request for member `setY' in `Rectangle::itsLowerLeft', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:23: request for member `setX' in `Rectangle::itsLowerRight', which is of non-aggregate type `int'
g:\c__tes~1\weekon~1\rect.cpp:24: request for member `setY' in `Rectangle::itsLowerRight', which is of non-aggregate type `int'


Jednostavno ne razumijem u cemu je problem... Jos sam pocetnik za c++ i jednostavno sve sto pokusam ne otklanja ove greske jer je vjerovatno problem negdje u sintaksi... Hvala unaprijed na pomoci!
[ Gogy @ 05.10.2005. 19:12 ] @
Izgleda da imas nekoliko gresaka u kodu.
Ono sto vidim:
1.)Zamijeni #include <rect.hpp> sa #include "rect.hpp"
2.)U puno funkcija (getUpperLeft(),getUpperLeft(),itd.) navodis kao povratni tip funckcije Point a ustvari vracas integer.

Rijesenje:
Mislim da trebas neke clanove (itsUpperLeft,itsLowerLeft,itsUpperRight,itsLowerRight) deklarirati kao Point umjesto integer i onda ce biti bolje. ;)

I jos nesto,imas dva puta deklariranu funckiju getUpperLeft():
Code:

  Point getUpperLeft() const {return itsUpperLeft;}
  Point getUpperLeft() const {return itsLowerLeft;}

Stoga komentiraj ili izbrisi jednu od njih.Ili preimenuj ovu zadnju u getLowerLeft.

Takodjer,trebas pozvati system("Pause") prije nego return(0) jer ti se inace system("Pause") nece izvrsiti i program ce se odmah zatvoriti.

Hope this helps!
[ TechnoChronox @ 05.10.2005. 19:55 ] @
Hvala Gogy, every effort is apreciated!

1) Nema veze kako se include fileovi deklarisu moze i sa <> i sa "" (bar sam tako procitao na nekoliko mjesta i uvjerio se da nema razlike)
2) Ovo mi je pomoglo da rijesim sve error-e, kao i neke ostale koje su se pojavili... Problem mi je bio u tome sto kad ti kompajler izbaci neki novi error sa kojim se nisi susretao tesko ga je razumijeti na sta se tacno odnosi... Uglavnom ovo mi je pomoglo.

Ovo sa return i system("pause") znam nego sam samo na kraju dodao return bez ikakvog razmisljanja... Anyway thx! Sto se mene tice tema se moze zakljucati...