elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Usando Git para manipular el directorio de trabajo, el índice y commits (segunda parte)


  Mostrar Temas
Páginas: [1]
1  Programación / Programación C/C++ / Ayuda Erroir error LNK2005 already defined en: 23 Julio 2011, 19:36 pm
Hola a todos yo por aca de nuevo  :xD

Esta vez con un proyecto en "MFC AppWizard (dll)"

el profesor no dios el ejercicio y hay que encontrar errores, luego de resolver el primero me tranque en el segundo error.

quisiera que le hechen un vistaso:


Complejo.cpp

Código
  1. //fichero main.cpp
  2. #include "stdafx.h"
  3. #include "complejo.h"
  4.  
  5. void main(void)
  6. {
  7. // declaración de números complejos
  8. complejo c1(1.0, 1.0);
  9. complejo c2(2.0, 2.0);
  10. complejo c3;
  11. c3.SetData(); //pide datos para c3
  12. complejo c4(4.0);
  13. // operadores aritméticos
  14. complejo suma = c1.Suma(c2); //c1+c2
  15. complejo resta = c1.Resta(c3); //c1-c3
  16. complejo producto = c2.Multiplica(c4); //c2*c4
  17. complejo cociente = c1.Cociente(c3); //c1/c3
  18. cout << "Primer complejo: "; c1.Prt();
  19. cout << "Segundo complejo: ";c2.Prt();
  20. cout << "Tercer complejo: "; c3.Prt();
  21. cout << "Suma: " ; suma.Prt();
  22. cout << "Resta: " ; resta.Prt();
  23. cout << "Producto: " ; producto.Prt();
  24. cout << "Cociente: " ; cociente.Prt();
  25. cout << "Ya he terminado." << endl;
  26. }
  27.  


StdAfx.cpp

Código
  1. // stdafx.cpp : source file that includes just the standard includes
  2. // complejo.pch will be the pre-compiled header
  3. // stdafx.obj will contain the pre-compiled type information
  4.  
  5. #include "stdafx.h"
  6.  
  7. #include "complejo.h"
  8.  
  9.  


Complejo.h

Código
  1. // fichero complejo.h
  2. #include <iostream.h>
  3. class complejo
  4. {
  5. private:
  6. double real;
  7. double imag;
  8. public:
  9. // Constructores
  10. complejo(); //defecto
  11. complejo(double, double im=0.0);
  12. // SetThings
  13. void SetData(void);
  14. void SetReal(double);
  15. void SetImag(double);
  16. // GetThings
  17. double GetReal(void){return real;}
  18. double GetImag(void){return imag;}
  19. //Operaciones
  20. complejo Suma(complejo c);
  21. complejo Resta(complejo c);
  22. complejo Multiplica(complejo c);
  23. complejo Cociente(complejo c);
  24. //Salida
  25. void Prt(){ cout << "("<< real <<","<< imag<<"i)"<<endl; }
  26. };
  27.  
  28.  
  29. complejo::complejo() // constructor por defecto
  30. {
  31. real = 0.0; imag = 0.0;
  32. }
  33. // constructor general
  34. complejo::complejo(double re,double im)
  35. {
  36. real = re; imag = im;
  37. }
  38. // función miembro SetData()
  39. void complejo::SetData(void)
  40. {
  41. cout << "Parte real: ";
  42. cin >> real;
  43. cout << "Parte imaginaria: ";
  44. cin >> imag;
  45. }
  46. void complejo::SetReal(double re)
  47. {
  48. real = re;
  49. }
  50. void complejo::SetImag(double im)
  51. {
  52. imag = im;
  53. }
  54. complejo complejo::Suma(complejo c)
  55. {
  56. complejo cs;
  57. cs.real = real + c.real;
  58. cs.imag = imag + c.imag;
  59. return cs;
  60. }
  61. complejo complejo::Resta(complejo c)
  62. {
  63. complejo cr;
  64. //escribir el código para restar
  65. cr.real = real - c.real;
  66. cr.imag = imag - c.imag;
  67. return cr;
  68. }
  69. complejo complejo::Multiplica(complejo c)
  70. {
  71. complejo cm;
  72. //escribir el código (a,b) * (c,d) = (ac-bd, ad+bc)
  73. cm.real = real * c.real;
  74. cm.imag = imag * c.imag;
  75. return cm;
  76. }
  77. complejo complejo::Cociente(complejo c)
  78. {
  79. complejo cc;
  80. //escribir (a,b)/(c,d) = ((ac+bd)/(c^2+d^2) , (bc-ad)/(c^2 + d^2 ))
  81. cc.real = real / c.real;
  82. cc.imag = imag / c.imag;
  83. return cc;
  84. }


StdAfx.h

Código
  1. // stdafx.h : include file for standard system include files,
  2. //  or project specific include files that are used frequently, but
  3. //      are changed infrequently
  4. //
  5.  
  6. #if !defined(AFX_STDAFX_H__7C1B2F84_8EEA_4865_9808_AB1551CD54C1__INCLUDED_)
  7. #define AFX_STDAFX_H__7C1B2F84_8EEA_4865_9808_AB1551CD54C1__INCLUDED_
  8.  
  9. #if _MSC_VER > 1000
  10. #pragma once
  11. #endif // _MSC_VER > 1000
  12.  
  13. #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
  14.  
  15. #include <afxwin.h>         // MFC core and standard components
  16. #include <afxext.h>         // MFC extensions
  17.  
  18. #ifndef _AFX_NO_OLE_SUPPORT
  19. #include <afxole.h>         // MFC OLE classes
  20. #include <afxodlgs.h>       // MFC OLE dialog classes
  21. #include <afxdisp.h>        // MFC Automation classes
  22. #endif // _AFX_NO_OLE_SUPPORT
  23.  
  24.  
  25. #ifndef _AFX_NO_DB_SUPPORT
  26. #include <afxdb.h> // MFC ODBC database classes
  27. #endif // _AFX_NO_DB_SUPPORT
  28.  
  29. #ifndef _AFX_NO_DAO_SUPPORT
  30. #include <afxdao.h> // MFC DAO database classes
  31. #endif // _AFX_NO_DAO_SUPPORT
  32.  
  33. #include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
  34. #ifndef _AFX_NO_AFXCMN_SUPPORT
  35. #include <afxcmn.h> // MFC support for Windows Common Controls
  36. #endif // _AFX_NO_AFXCMN_SUPPORT
  37.  
  38.  
  39.  
  40. //{{AFX_INSERT_LOCATION}}
  41. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  42.  
  43. #endif // !defined(AFX_STDAFX_H__7C1B2F84_8EEA_4865_9808_AB1551CD54C1__INCLUDED_)
  44.  


Al Compilar tengo 0 Errores, pero al Ejecutar me da esto:

Código:
StdAfx.obj : error LNK2005: "public: __thiscall complejo::complejo(void)" (??0complejo@@QAE@XZ) already defined in complejo.obj
StdAfx.obj : error LNK2005: "public: __thiscall complejo::complejo(double,double)" (??0complejo@@QAE@NN@Z) already defined in complejo.obj
StdAfx.obj : error LNK2005: "public: void __thiscall complejo::SetData(void)" (?SetData@complejo@@QAEXXZ) already defined in complejo.obj
StdAfx.obj : error LNK2005: "public: void __thiscall complejo::SetReal(double)" (?SetReal@complejo@@QAEXN@Z) already defined in complejo.obj
StdAfx.obj : error LNK2005: "public: void __thiscall complejo::SetImag(double)" (?SetImag@complejo@@QAEXN@Z) already defined in complejo.obj
StdAfx.obj : error LNK2005: "public: class complejo __thiscall complejo::Suma(class complejo)" (?Suma@complejo@@QAE?AV1@V1@@Z) already defined in complejo.obj
StdAfx.obj : error LNK2005: "public: class complejo __thiscall complejo::Resta(class complejo)" (?Resta@complejo@@QAE?AV1@V1@@Z) already defined in complejo.obj
StdAfx.obj : error LNK2005: "public: class complejo __thiscall complejo::Multiplica(class complejo)" (?Multiplica@complejo@@QAE?AV1@V1@@Z) already defined in complejo.obj
StdAfx.obj : error LNK2005: "public: class complejo __thiscall complejo::Cociente(class complejo)" (?Cociente@complejo@@QAE?AV1@V1@@Z) already defined in complejo.obj
StdAfx.obj : warning LNK4006: "public: __thiscall complejo::complejo(void)" (??0complejo@@QAE@XZ) already defined in complejo.obj; second definition ignored
StdAfx.obj : warning LNK4006: "public: __thiscall complejo::complejo(double,double)" (??0complejo@@QAE@NN@Z) already defined in complejo.obj; second definition ignored
StdAfx.obj : warning LNK4006: "public: void __thiscall complejo::SetData(void)" (?SetData@complejo@@QAEXXZ) already defined in complejo.obj; second definition ignored
StdAfx.obj : warning LNK4006: "public: void __thiscall complejo::SetReal(double)" (?SetReal@complejo@@QAEXN@Z) already defined in complejo.obj; second definition ignored
StdAfx.obj : warning LNK4006: "public: void __thiscall complejo::SetImag(double)" (?SetImag@complejo@@QAEXN@Z) already defined in complejo.obj; second definition ignored
StdAfx.obj : warning LNK4006: "public: class complejo __thiscall complejo::Suma(class complejo)" (?Suma@complejo@@QAE?AV1@V1@@Z) already defined in complejo.obj; second definition ignored
StdAfx.obj : warning LNK4006: "public: class complejo __thiscall complejo::Resta(class complejo)" (?Resta@complejo@@QAE?AV1@V1@@Z) already defined in complejo.obj; second definition ignored
StdAfx.obj : warning LNK4006: "public: class complejo __thiscall complejo::Multiplica(class complejo)" (?Multiplica@complejo@@QAE?AV1@V1@@Z) already defined in complejo.obj; second definition ignored
StdAfx.obj : warning LNK4006: "public: class complejo __thiscall complejo::Cociente(class complejo)" (?Cociente@complejo@@QAE?AV1@V1@@Z) already defined in complejo.obj; second definition ignored
   Creating library Debug/complejo.lib and object Debug/complejo.exp
Debug/complejo.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.


Tengo rato buscando el error y no doy, segun veo en foros gringos que leo, que el problema es en las cabezeras pero nada no doy  :-\


Salu2
2  Programación / Programación C/C++ / Programa para Llevar de TB a GB,MB,KB... en: 26 Junio 2011, 19:03 pm
Hola a todos :D no soy nuevo en el foro por que me registre hace quien sabe cuanto xD. pero si es primera vez que posteo... estoy estudiando programacion y ya nos estan metiendo C++ pero hasta ahora empezando asi que soy noob en esto todavia  :xD

Para clases el professor pidio un programa para llevar de TB a GB,MB,KB...

y pues yo lo tengo asi:

Código:
#include <stdio.h>
#include <stdlib.h>
main()
{
int tb,gb,mb,kb,bytes;
printf("----> Programa Para Llevar de TB a GB,MB,KB,Bytes <---- \n");
printf("\n");
printf("Introduzca La Cantidad de TB: \n");
scanf("%d",&tb);
gb=tb*1024;
mb=gb*1024;
kb=mb*1024;
bytes=kb*1024;

printf("El Resultado en GB es= %d  \n",gb);
printf("El Resultado en MB es= %d  \n",mb);
printf("El Resultado en KB es= %f \n",kb);
printf("El Resultado en Bytes es= %f \n",bytes);
printf("\n");
system ("pause");
return 0;

}

El programa me da el resultado en GB y Mb pero KB y Bytes no me da, estoy casi seguro que es el "%f" pero no se por cual cambiar, recordar que ando empezando en esto  :¬¬

Aja el programa esta con prinft, scanft... asi nos enseño la profesora antigua, ahora el nuevo viene a decir que empezemos a usar :"#include <iostream>" y  el cout entre otros, que opinan de esto no es lo mismo?

Salu2 y Gracias  ;D
Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines