Problem: Fehler in Programm, wieso?

int0xicated

Grünschnabel
Hallo!

Vielleicht liegt es an der Uhrzeit, oder was weiß ich, aber ich komm einfach nicht drauf, was ich für einen fehler ich in meinem "programmgrundgerüst" habe...
ich habe 3 files: die main klasse, die klasse logfile.cpp und die header datei zu logfile.cpp

mein problem: was mache ich falsch, dass ich diese funktion (siehe unten, die rotmarkierte) nicht anwenden kann? Um sich ein bild zu machen hänge ich mal alle 3 files (nur die wichtigen stellen) an (die roten stellen erzeugen den fehler)

die main klasse (iostring.cpp):

Code:
#include <iostream>
#include <fstream>
#include "logfile.h"

using namespace std;
int main()
{  
   
   ifstream Quelle;
   ofstream Ziel;
   
      char c = 0;
      
     
      logfileConstants(void);//hier

header datei logfile.h

Code:
#ifndef LOGFILE_H_
#define LOGFILE_H_

class logfile {

public:
	void logfileConstants();//string m, string n, string code, string path, string stream
	void loadExistingLogfile();
	void createLogfile();
	
};
#endif /*LOGFILE_H_*/


logfile.cpp:

Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;



void logfileConstants()//string M, string N, string code, string path, string stream
{

	 //...
}

void createLogfile() {

	
}

void loadExistingLogfile() {
	
}


ERRORLOG:

Code:
**** Rebuild of configuration Debug for project MaoMao ****

**** Internal Builder is used for build               ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -oiostring.o ..\iostring.cpp
..\iostring.cpp: In function `int main()':
..\iostring.cpp:16: error: expected primary-expression before "void"
..\iostring.cpp:16: error: `logfileConstants' was not declared in this scope
..\iostring.cpp:16: warning: unused variable 'logfileConstants'
Build error occurred, build is stopped
Time consumed: 625  ms.

hoffe ihr könnte mir helfen, thx in advance!

mfg
 
hi,

ich behaupte mal, dass du die logfile.cpp und nicht logfile.h einbinden solltest ;)
wenn michnciht alles täuscht solltest du auchin logfile.h die voids in private: private slots:
reinpacken... (sonst hast du vermutlich eine multiple definition...)und dann sollte es gehen

lg
eXo

#edit: in logfile.cpp noch die logfile.h einbinden...
 
Zuletzt bearbeitet:
Du musst bei der Implementierung der Methoden logfile:: vor den Methodennamen schreiben.

und das #edit von kickerxy123 nicht vergessen!

Gruß
MCoder
 
Zuletzt bearbeitet:
danke, aber jetzt bekomme ich nur noch den fehler: "expected primary-expression before void" in der iostring.cpp (bei logfi.leconstans(void)).. wieso will das nicht funktionieren? :(
 
Hallo,

das void hat an dieser Stelle nichts zu suchen. Außerdem musst du erst eine Instanz der Klasse logfile erstellen, um die Instanzmethode aufrufen zu können.

Grüße,
Matthias
 
ok ... das hab ich auch schon probiert, aber dann kommt ein linker error, aber wieso?


**** Rebuild of configuration Release for project logfile ****

**** Internal Builder is used for build ****
g++ -O3 -Wall -c -fmessage-length=0 -ologfile.o ..\logfile.cpp
..\logfile.cpp:77:4: warning: no newline at end of file
g++ -O3 -Wall -c -fmessage-length=0 -oiostring.o ..\iostring.cpp
g++ -oMaoMao.exe logfile.o iostring.o
iostring.o:iostring.cpp:(.text+0x1ed): undefined reference to `logfile::logfileConstants()'
collect2: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 1890 ms.
 
an der logfile habe ich das, was kickerxy ("private: private slots:") ausprobiert, aber bei private slots bekomm ich eine fehlermeldung drum hab ich die funktionen public gelassen... (ich weiß auch nicht, was das private slots bewirken soll)

ganze logfile.cpp

Code:
#include <iostream>
#include <fstream>
#include <string>
#include "logfile.h"

using namespace std;


void logfileConstants()//string M, string N, string code, string path, string stream
{

	   ifstream Quelle;
	   ofstream Ziel;
	   
	      char c = 0;
	      
	      
	      char fname1[] = "C:\\TEST.txt", fname2[] = "C:\\abcd.bak";
	     
	      Quelle.open(fname1,ios::binary | ios::in);
	      if (!Quelle)
	         cout << "\nDatei " << fname1
	              << " konnte nicht geöffnet werden!" << endl;
	      else
	      {  Ziel.open(fname2,ios::binary | ios::out);
	         if (!Ziel)
	            cout << "\nDatei " << fname2
	                 << " konnte nicht geöffnet werden!" << endl;
	         else
	        	 //cout<<"gehst du hier rein?";
	        	 
	        	 while(Quelle.get(c)){
	        		cout<<"dfasfas";
	        		 cout<<"gehst du hier rein?";
	               Ziel.put(c);
	               
	             
	        	 }
	         Ziel.close();
	      }
	      _fcloseall(); // alle Dateien schließen
	cout<<"hallo warum gehst du nicht?";
	   
	   
	   /*
	   ofstream file2(path); // Öffnen der Datei in die umgeleitet werden soll
	   cout.rdbuf(file.rdbuf()); // umleitung "anordnen"
	   cout << "Hello World" << endl; // Test ausgabe 
	*/
}

void createLogfile() {

	
}

void loadExistingLogfile() {
	
}

die main:


Code:
#include <iostream>
#include <fstream>
#include "logfile.h"

using namespace std;


int main()
{  
   
   ifstream Quelle;
   ofstream Ziel;
   
      char c = 0;
      
      logfile cpp;
      
      cpp.logfileConstants();
...
}

die logfile.h

Code:
#ifndef LOGFILE_H_
#define LOGFILE_H_


class logfile {

public:
	void logfileConstants();//string m, string n, string code, string path, string stream
	void loadExistingLogfile();
	void createLogfile();
	
};
#endif /*LOGFILE_H_*/
 
C++:
void logfile::logfileConstants() ...
void logfile::createLogfile() ...
void logfile::loadExistingLogfile() ...
... hatte ich doch schon geschrieben :rolleyes:

Der Tip mit mit den "private slots" ist hier wohl fehl am Platz; das gehört zur Qt-Programmierung.

Gruß
MCoder
 
so hast du das gemeint :P ... ich hatte das ganze so logfile:: void methodenname öÖ
aufjedenfall gehts jetzt VIELEN DANK! hrhr, aber ich verstehe nicht, wieso ich "logfile::" noch davor hinschreiben sollte, denn eigentlich ist das ganze ja schon included ... aber aufjedenfall danke
 
Zurück