Unix Programming - is gcc a c++ compiler

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > January 2004 > is gcc a c++ compiler





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author is gcc a c++ compiler
Tommy

2004-01-23, 5:01 pm

Hi call,

"man gcc" stated that gcc is a c++ compiler. However, I have the following
*VERY SIMPLE* code in c++ that doesn't compile in gcc. It compiles fine in
VC++ 7.0. I have no clue why. TIA

Error message:
gcc test.cc
/tmp/ccMJrkgw.o(.text+0x18): In function `main':
: undefined reference to `Point::Point[in-charge]()'
/tmp/ccMJrkgw.o(.text+0x3f): In function `main':
: undefined reference to `Point::Point[in-charge](double, double)'
/tmp/ccMJrkgw.o(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status



test.cc:
#include "Point.h"
#include <stdio.h>

int main()
{
Point a;
Point b(3, 4);
//printf("Distance is %f", a.getDistance(b));
return 0;
}

Point.h:
#ifndef Point_H
#define Point_H

class Point
{
private:
double m_x, m_y;

public:
Point();
Point(double x, double y);
double getDistance(Point p);
void setPoint(double x, double y);
double getX();
double getY();

};

#endif


Point.cc:
#include "Point.h"
#include <math.h>

Point::Point()
{
setPoint(0, 0);
}

Point::Point(double x, double y)
{
setPoint(x, y);
}

void Point::setPoint(double x, double y)
{
m_x = x;
m_y = y;
}
double Point::getX()
{
return m_x;
}
double Point::getY()
{
return m_y;
}

double Point::getDistance(Point p)
{
return pow(pow(p.getX() - m_x, 2) + pow(p.getY() - m_y, 2), 0.5);
}

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com