0

I keep getting this problem. After learning about inheritance and understanding classes and constructors I can't see why this is happening. In a lab for school I made three classes connecting them with inheritance. While testing my three default constructors and general ones, Xcode is basically saying it doesn't see my constructors. To keep the question short this is one of my three classes. I'm working on Xcode version 7.2 practicing C++.

I've searched far and wide on the internet. This isn't an exact duplicate of anything. If I found my answer I would spend this time posting this.

#ifndef Point2D_h
#define Point2D_h
#include<iostream>


using namespace std;

class Point2D{

private:
    int x;
    int y;

public:
Point2D();
Point2D(int xx, int yy):x(xx),y(yy){}
int getX(){ return x;};
int getY(){ return y;};
void setX(int newX){ x = newX;}
void sety(int newY){ y = newY;}
void Print(){ cout << x <<" " << y;}
bool Equal(Point2D);

};

  #endif /* Point2D_h */
 -------------------Main------------------------   
#include <iostream>
#include "Point2D.h"
#include "Circle.h"
#include "Cylinder.h"
#include "Point2D_Functions.cpp"
#include "Cylinder_Functions.cpp"
#include "Standard_Functions.cpp"

using namespace std;

int main(){

    Point2D p1;


     return  0; 

}

ERRORS:

1) Point2D::Point2D() , referenced from:
2) Linker command failed withe exit code 1(use -v to see invocation)

When testing the other default constructors like Circle or Cylinder, I get the same error just with the different name in the error like Circle::Circle()...

Vin...C
  • 1
  • 6
  • 1
    Where do you define `Point2D()`? – NathanOliver Feb 20 '17 at 20:16
  • In my class Point2D in the public section. – Vin...C Feb 20 '17 at 20:19
  • 1
    That is a declaration. Where is the part that has the {} and initializes the member variables? – NathanOliver Feb 20 '17 at 20:20
  • @Vin...C That's not a _definition_. – πάντα ῥεῖ Feb 20 '17 at 20:20
  • It's a default constructor. Default constructors get called right?. They aren't really functions they allow you to make an object. Xcode is treating it like a function. I just want to make an object. – Vin...C Feb 20 '17 at 20:23
  • you are including cpp files, that could cause more errors `#include "Point2D_Functions.cpp"` include`.h` or `.hpp` instead – Rama Feb 20 '17 at 20:25
  • @Vin...C The defenition of a default constructor looks like `Foo() {}` or better yet `Foo() = default;` – NathanOliver Feb 20 '17 at 20:26
  • @Rama , hey that worked, I commented out all the .cpp files and it works, but I'd obviouly like to use the functions I made in those. Wonder how I can get it to work. – Vin...C Feb 20 '17 at 20:35
  • @Vin...C Maybe you can research a little bit more about headers files, and how to organize your project: http://stackoverflow.com/questions/6995572/using-multiple-cpp-files-in-c-program – Rama Feb 20 '17 at 20:41

0 Answers0