louisz90 发表于 2018-3-5 20:59:04

找不到main函数入口的问题

#include "pt.h"
#include <iostream>
#include <math.h>

using namespace std;

pt::pt(int x, int y)
{

        (*this).x = x;
        (*this).y = y;

}

void pt::afficher()
{

        cout << "(" << (*this).x << "," << (*this).y << ")";

}

void pt::deplacer(int dx, int dy)
{

        (*this).x += dx;
        (*this).y += dy;

}

void pt::saisir()
{

        cout << "Entrer la valeur de x: ";
        cin >> (*this).x;

        cout << "Entrer la valeur de y: ";
        cin >> (*this).y;

}

// Le cosntructeur est une fonction qui ne cr茅e pas l'objet mais qui accompagne la cr茅ation de fa?on 脿 ce que l'objet soit pr锚t 脿 l'utilisation.

float pt::distance(pt & p)
{
        float dx=((*this).x-p.x);
        float dy=((*this).y-p.y);
        return (sqrtf(dx*dx+dy*dy));

}


void pt::deplacer(pt &p)
{

        (*this).x += p.x;
        (*this).y += p.y;

}

bool pt::identique(pt & p)
{
        float d;
        d=(*this).distance(p);
        if(d<0.01) return true;
        else return false;
}

// Q4
pt::pt(const pt &p)
{
        (*this).x=p.x;
        (*this).y=p.y;
}

// pour Q7
int pt::getx()
{
        return((*this).x);
}

int pt::gety()
{
        return((*this).y);
}

void pt::putx(int x)
{
        (*this).x=x;       
}

void pt::puty(int y)
{
        (*this).y=y;       
}





在法国留学 这是老师给的答案 我怎么改都没有用,他说可能是我编译器的问题,我用的dev-c
求大神解释一下呀

louisz90 发表于 2018-3-5 21:03:17

三个文件 我打包了 感兴趣的可以看看

人造人 发表于 2018-3-5 23:08:07

重新建立一个工程,建立的时候选 控制台应用程序
你现在的是 win32窗口程序,入口是WinMain
控制台应用程序的入口是 main

BngThea 发表于 2018-3-6 09:19:34

你的代码中确实没有main函数啊{:10_266:}

风过无痕丶 发表于 2018-3-6 09:52:54

本帖最后由 风过无痕丶 于 2018-3-6 10:04 编辑

好尴尬啊。。。我居然让他跑起来了。。。
方法嘛~ 三楼正解~

Q爸爸 发表于 2018-3-6 10:43:35

看起来好厉害

louisz90 发表于 2018-3-8 05:09:54

人造人 发表于 2018-3-5 23:08
重新建立一个工程,建立的时候选 控制台应用程序
你现在的是 win32窗口程序,入口是WinMain
控制台应用程 ...

我把三个文件内容放到一个里面也可以运行 但是分开就不行啊

louisz90 发表于 2018-3-8 05:10:44

风过无痕丶 发表于 2018-3-6 09:52
好尴尬啊。。。我居然让他跑起来了。。。
方法嘛~ 三楼正解~

我觉得是我编译器的问题

louisz90 发表于 2018-3-8 05:46:51

最后变成这样了

人造人 发表于 2018-3-8 08:57:45

louisz90 发表于 2018-3-8 05:46
最后变成这样了

把图截完整,尤其是画红线的位置

人造人 发表于 2018-3-8 08:59:18

louisz90 发表于 2018-3-8 05:46
最后变成这样了

#include <pt.h>
改为
#include "pt.h" // pt.h文件要和当前这个文件在同一个目录

roluce 发表于 2018-3-10 06:25:39

好复杂,晕了。。。。{:10_269:}

louisz90 发表于 2018-3-10 18:38:15

人造人 发表于 2018-3-8 08:59
#include
改为
#include "pt.h" // pt.h文件要和当前这个文件在同一个目录

不好意思 这几天课多 没看到

louisz90 发表于 2018-3-10 18:39:20

其实一开始都是对的 给老师看也检查不出来问题 说是编译器的问题

louisz90 发表于 2018-3-10 18:40:48

就是找不到pt文件

人造人 发表于 2018-3-10 18:51:05

louisz90 发表于 2018-3-10 18:40
就是找不到pt文件

把 pt.h 文件改成这样,其他不变

#ifndef _PT_H_
#define _PT_H_

class pt
{
        private:
                int x;
                int y;

        public:
                pt(int x = 0, int y = 0); // les valaurs par défaut sont (0,0).
                void afficher();
                void deplacer(int dx, int dy);
                void saisir();
                void deplacer(pt &p);
                float distance(pt &p);
                bool identique(pt &p);
                // Q4
                pt(const pt &p);
                // des accesseurs pour la question Q7
                int getx();
                int gety();
                // des accesseurs pour la question Q7
                void putx(int x);
                void puty(int y);
};

#endif



sh-4.4$ ls
main.cpppt.cpppt.h
sh-4.4$ g++ main.cpp pt.cpp -Wall
sh-4.4$ ls
a.exemain.cpppt.cpppt.h
页: [1]
查看完整版本: 找不到main函数入口的问题