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

    [Visual C++] includere una classe in un progetto

    Salve,

    ho una classe composta da due files: myclass.h e myclass.cpp che vorrei usare in un progetto. In VC++ creo un progetto nuovo ed un file main.cpp in qui scrivo:

    codice:
    #include <stdio.h>
    #include "myclass.h"
    
    int main()
    {
    	myclass* C = new myclass();
    	(...)
    	delete C;
    	return 0;
    }
    Ora, a dire il vero nella "Solution Explorer" di VC++ non incluso i files della classe in quanto credevo bastasse che fossero presenti nella folder del progetto:

    .../Visual Studio 2008/Projects/myproject/myproject/main.cpp, myclass.h, myclass.cpp and Debug folder along with a file USER.

    Ora quando debuggo il progetto ottengo: "unresolved external symbol" sia nel costruttore che nel distruttore.

    Non riesco a capire cosa non va, ho provato lo stesso includendo un file myclass.obj ottenuto dalla compilazione di myclass.cpp ma niente....

    grazie
    Alla batteria dai retta ballA

  2. #2
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Project -> Add Existing Item e cerchi il file da aggiungere al progetto.
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

  3. #3
    e dove lo aggiungerà? nel cartella source resource o header? il fatto è che quando includo il file header via codice (#include) me lo vede...posso aggiungere anche un file object?
    Alla batteria dai retta ballA

  4. #4
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    Lo visualizza in Source Files del Solution explorer.
    Li puoi aggiungere files .c, .cpp, .obj, .lib; cioè tutti quei file che contengono codice sorgente o codice compilato.
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

  5. #5
    ok, perfetto. tutto funziona e con velocità incredibile, anche se però ottengo questo warning:

    1>------ Build started: Project: usemyclass, Configuration: Debug Win32 ------
    1>Compiling...
    1>main.cpp
    1>Linking...
    1>waveCapture.obj : MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG; add /LTCG to the link command line to improve linker performance
    1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
    1>Generating code
    1>Finished generating code
    1>Embedding manifest...
    1>Build log was saved at "file://c:\Users\giangaetano\Documents\Visual Studio 2008\Projects\usemyclass\usemyclass\Debug\BuildLog .htm"
    1>usemyclass - 0 error(s), 1 warning(s)
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
    per il resto tutto a posto!
    Alla batteria dai retta ballA

  6. #6
    Utente di HTML.it L'avatar di shodan
    Registrato dal
    Jun 2001
    Messaggi
    2,381
    E' un warning che ottengo spesso anche io, quando inserisco librerie create da me. Non ho mai capito perché, nonostante vari tentativi di cambiare opzioni, ricerche su Internet etc.
    Mai avuto un problema però.

    1>------ Build started: Project: usemyclass, Configuration: Debug Win32 ------
    E' meglio se nel progetto metti il file .cpp invece del .obj. In modalità Release verra ricompilato adottando le ottimizzazioni del caso, mentre il .obj verrà solo linkato.
    This code and information is provided "as is" without warranty of any kind, either expressed
    or implied, including but not limited to the implied warranties of merchantability and/or
    fitness for a particular purpose.

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 © 2025 vBulletin Solutions, Inc. All rights reserved.