Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    [C++]Problema con Costruttore

    Ho il seguente cod:
    codice:
    // Screen.h
    #ifndef SCREEN_H
    #define SCREEN_H
    
    class Screen
    {
        public:
            Screen(int x, int y);
            ~Screen();
            inline int cursor() const { return _cursor; }
        private:
            int _cursor,_x,_y;
    };
    
    #endif
    codice:
     // Screen.cpp
    #include "Screen.h"
    
    Screen::Screen(int x, int y): x(_x), y(_y)
    {
        _cursor = x/y;
    }
    
    Screen::~Screen()
    {
        delete _x, _y, _cursor;
    }
    codice:
     
    // Test.cpp
    #include <cstdio>
    #include <iostream>
    #include "Screen.h"
    
    using namespace std;
    
    int main()
    {
        int i=5, j=10;
        Screen *ptrSc = new Screen(i, j);
        cout << ptrSc->cursor() <<endl;    
        system("PAUSE");
        return 0;
    }
    Ma mi da:
    Compilatore: C++ Optimized Maximum
    Esecuzione di g++.exe...
    g++.exe "C:\Documents and Settings\Admin\Desktop\Screen\Test.cpp" -o "C:\Documents and Settings\Admin\Desktop\Screen\Test.exe" -fexpensive-optimizations -O2 -I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32" -I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
    C:\DOCUME~1\Admin\IMPOST~1\Temp/ccY5aaaa.o(.text+0x39):Test.cpp: undefined reference to `Screen::Screen(int, int)'

    Esecuzione terminata
    La stupidità umana e l'universo sono infinite.
    Della seconda non sono certo(Einstein)

    Gnu/Linux User

  2. #2
    Nel file principale devi includere Scree.cpp e non Screen.h.

    Bye
    There are 10 kinds of people in the world: who knows the binary numeration and who not

  3. #3
    Originariamente inviato da TheGreatWorld
    Nel file principale devi includere Scree.cpp e non Screen.h.

    Bye
    giusto!
    Sto testando nu paio di cosse
    La stupidità umana e l'universo sono infinite.
    Della seconda non sono certo(Einstein)

    Gnu/Linux User

  4. #4
    :metallica
    La stupidità umana e l'universo sono infinite.
    Della seconda non sono certo(Einstein)

    Gnu/Linux User

  5. #5
    Risolto cosi:
    codice:
    // Test.cpp
    #include <cstdio>
    #include <iostream>
    #include "Screen.cpp"
    
    using namespace std;
    
    int main()
    {
        int i=15, j=5;
        Screen *ptrSc = new Screen(i, j);
        cout << "Il puntatore e' a: "<< ptrSc->cursor() <<endl;    
        system("PAUSE");
        return 0;
    }
    Tnk TGW
    La stupidità umana e l'universo sono infinite.
    Della seconda non sono certo(Einstein)

    Gnu/Linux User

  6. #6
    ma non basta inserire il file nel progetto perchè lo veda? :master:
    non credo che si debba includere un .cpp (anche se funziona) ma solo il .h

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.