Fórum Ubuntu CZ/SK
Ubuntu pro osobní počítače => Software => Příkazový řádek a programování pro GNU/Linux => Téma založeno: LorD_OniX 28 Dubna 2009, 01:13:37
-
Ahoj, mam nasledujici data po souborech:
// trida pro server server.h
class classServer
{
public:
classServer();
~classServer();
// metody
void test();
};
// definice tridy server.cpp
// konstruktor tridy
classServer::classServer()
{
}
// destruktor tridy
classServer::~classServer()
{
}
void classServer::test()
{
cout << "test" << endl;
}
// podrazena trida, ktera bude dedit server tridu classClient.h
#include "classServer.h"
// trida pro vytvoreni clienta
class classClient : public classServer
{
public:
classClient();
~classClient();
};
// definice classClient.cpp
classClient::classClient()
{
}
classClient::~classClient()
{
}
// nekde v mainu si pak vytvorim instanci tridy classClient a budu si chtit zavolat zdedenou metodu test
classClient pom;
pom.test();
Ovsem toto nikdy nenastane a vypisi se nasledujici chyby:
client.o: In function `classClient':
/home/lordonix/Plocha/IPK/icpProjekt/classClient.h:28: undefined reference to `classServer::classServer()'
classClient.o: In function `~classClient':
/home/lordonix/Plocha/IPK/icpProjekt/classClient.cpp:13: undefined reference to `classServer::~classServer()'
/home/lordonix/Plocha/IPK/icpProjekt/classClient.cpp:13: undefined reference to `classServer::~classServer()'
classClient.o: In function `classClient':
/home/lordonix/Plocha/IPK/icpProjekt/classClient.cpp:4: undefined reference to `classServer::classServer()'
/home/lordonix/Plocha/IPK/icpProjekt/classClient.cpp:4: undefined reference to `classServer::classServer()'
collect2: ld returned 1 exit status
make: *** [client] Error 1
Konstruktory, destruktory se nededi a neustale to pise takove chyby :( Nevim si s tim rady, predem diky za odpoved.
-
nema byt nahodou namiesto "class classClient : public classClient" toto:
class classClient : public ClassServer
vidim ze som uz dlho v c++ nerobil, tak si nie som isty, len mi to nejak bije do oci
-
Promin to mas pravdu, jsem to mel spatne vlozene do kodu. Toto neni ta chyba, to je jenom chyba pri vkladani do fora.
-
bud chvilu na drate, skusim to nahadzat do netbeans :)
-
diky moc :) ja budu online jeste dlouho
-
No mne to ide
main:
/*
* File: newmain.cpp
* Author: peter
*
* Created on Utorok, 2009, apríl 28, 1:35
*/
#include <stdlib.h>
#include <iostream>
#include "Client.h"
/*
*
*/
int main(int argc, char** argv) {
classClient c;
c.test();
return (EXIT_SUCCESS);
}
server.h
/*
* File: Server.h
* Author: peter
*
* Created on Utorok, 2009, apríl 28, 1:35
*/
#ifndef _SERVER_H
#define _SERVER_H
class classServer
{
public:
classServer();
~classServer();
// metody
void test();
};
// definice tridy server.cpp
// konstruktor tridy
classServer::classServer()
{
}
// destruktor tridy
classServer::~classServer()
{
}
void classServer::test()
{
std::cout << "test" << std::endl;
}
#endif /* _SERVER_H */
Client.h
/*
* File: Client.h
* Author: peter
*
* Created on Utorok, 2009, apríl 28, 1:35
*/
#ifndef _CLIENT_H
#define _CLIENT_H
#include "Server.h"
// trida pro vytvoreni clienta
class classClient : public classServer
{
public:
classClient();
~classClient();
};
// definice classClient.cpp
classClient::classClient()
{
std::cout << "Som v konstruktore...ide to, pustam fciu test: \n";
}
classClient::~classClient()
{
}
#endif /* _CLIENT_H */
-
porovnaj si to s mojim, jedine co som pridal, bolo std:: a na zaciatku mainu #include <iostream>
-
Diky moc za snahu, ja to prekladam v g++, CFLAGS=-Wall -g -pedantic, LDFLAGS=-lm. Dneska jsem upgradoval ubuntu na 9.04, nevim jestli se nezmenila i posledni verze g++, jestli tam nejsou treba buggy :(
-
porovnaj si to s mojim, jedine co som pridal, bolo std:: a na zaciatku mainu #include <iostream>
no ja mam vsude v headerech naincludovane using namespace std; a taky <iostream> jak si psal ty. Ale nefunguje to
-
Posli makefile, podle mne je chyba tam
-
No vypadá to dobře. Takže spíše překladač neví o tom souboru, kde se to definuje. Takže asi ten makefile. Zkuste pro srandu králikům vypustit dědičnost a zkuste to skompilovat bez ní. A myslím si že to taky asi nepůjde. :)
-
Tak bez dedicnosti me preklad funguje bez chyby. Mam se i presto dat ten makefile ? Prominte ze odepisuju pozdeji, ve skole bylo dost projektovani a jeden velky projekt v Qt :)
-
Tak bez dedicnosti me preklad funguje bez chyby. Mam se i presto dat ten makefile ? Prominte ze odepisuju pozdeji, ve skole bylo dost projektovani a jeden velky projekt v Qt :)
No nejspíš je chyba tam tak vyzkoušejte ;)