0

Здравствуйте!

Пишу программу в VS 2010 на C++. Помогите, пожалуйста, ошибку, которая возникла из-за перегруженности функции. Где перегружается, я знаю, но почему, не пойму. Ведь самое интересно в том, что когда в классе наводишь мышку на его описание, оно выводит данный код, а при его использование пишите переопределению со всеми вытекающими. Задачи программы состоит в вычислении и нахождении координат точки на координатной плоскости. Ошибка возникла при написании функции увеличения.

Программа состоит из 3 файлов.

usePixel.cpp:

#include<iostream>
#include "Point.h"
#include "Pixel.h"

using namespace std;

int main()
{
    cout << Pixel::GetK() << endl;
    {
    Pixel a(10,20,Pixel::red);
    cout<<"Pixel a: "; a.Print(); cout << endl;

    cout << Pixel::GetK() << endl;

    Pixel b (Point(30,40), Pixel::blue);
    cout<<"Pixel b: "; b.Print(); cout << endl;

    cout << Pixel::GetK() << endl;

//  b.SetColor(Pixel::green);
    b.Move(10,20);
    cout<<"Pixel b: "; b.Print(); cout << endl;

    cout << "Dist = " << a.Dist(b) << endl;
    cout << "Color of Pixel b= " << b.GetColor() << endl;

    Pixel c = a;
    cout<<"Pixel c: "; c.Print(); cout << endl;

    system("pause");
    }

    cout << Pixel::GetK() << endl;
}

Pixel.cpp:

#include<iostream>
#include "Pixel.h"

using namespace std;

int Pixel::k = 0;

Pixel::Pixel(int x, int y, const  Color &clr)
: p(x,y), c(clr)
{ ++k; }

Pixel::Pixel(const Point &pt, const  Color &clr)
: p(pt), c(clr)
{ ++k; }

 //Ошибка тут начинается
Pixel::Pixel(const Point &px)
: p(px.p), c(px.c)
{ ++k; }
//Тут заканчивается

Pixel::~Pixel()
{  -- k;}

//==========================================

const Pixel::Color & Pixel::GetColor()const
{
    return c;
}
/*
void Pixel::SetColor(const Color &clr)
{
    //c= clr;
}
*/
void Pixel::Move (int delta_x, int delta_y)
{
    p.Move(delta_x, delta_y);
}

double Pixel::Dist(const Pixel &px)const
{
    return p.Dist(px.p);
}

void Pixel::Print()const
{
    p.Print();
    cout << c;
}

Pixel.h:

#pragma once
#include "point.h"

class Pixel
{
public:
    enum Color{black, blue, green, red = 4, yellow = 14, white};
    Pixel(int = 0, int = 0, const  Color& = black);
    Pixel(const Point &, const  Color& = black);
    Pixel(const Pixel &);
    ~Pixel();

    const Color & GetColor()const;
    //void SetColor(const Color &);

    void Move (int delta_x, int delta_y);
    double Dist(const Pixel &)const;

    void Print()const;

    static int GetK() { return k+n; }

private:
    Point p;
    const Color c;
    static int k;
    static const int n = 100;
};

Ошибка VS 2010:

1>------ Построение начато: проект: Pixel, Конфигурация: Debug Win32 ------
1>Построение начато 15.02.2012 18:41:27.
1>InitializeBuildStatus:
1>  Обращение к "Debug\Pixel.unsuccessfulbuild".
1>ClCompile:
1>  Pixel.cpp
1>c:\users\vladislav\documents\visual studio 2010\projects\pixel\pixel\pixel.cpp(18): error C2511: Pixel::Pixel(const Point &): перегруженная функция-член не найдена в "Pixel"
1>          c:\users\vladislav\documents\visual studio 2010\projects\pixel\pixel\pixel.h(7): см. объявление "Pixel"
1>c:\users\vladislav\documents\visual studio 2010\projects\pixel\pixel\pixel.cpp(52): fatal error C1004: непредвиденное обнаружение конца файла
1>
1>СБОЙ построения.

Благодарю!

1 ответ 1

5

У вас функция обьявлена как

Pixel(const Pixel &);

а определена как

Pixel::Pixel(const Point &px)

Pixel и Point - разные классы.

1
  • Спасибо! Я правда уже сам нашёл. Вопрос закрыт, ответ найден. 23 фев 2012 в 6:29

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.