PDA

View Full Version : Strange compilation error : undefined reference to ...



pl01
3rd December 2010, 13:39
Hi,

I'm using QT Creator 2.1 under Win7 and with the following code I got this error :

error: undefined reference to `File::file_exists(QString const&) const'

The code

if ( _myfile.file_exists("test.txt") )

The class code

bool file_exists(const QString & file) const;

I have the same problem with other files, by example


FinancialCategory* category = ...;
Product::get( category );

...

namespace Product {
bool get(Category* c)
}


And I got this error : error: undefined reference to `Product::get(FinancialCategory* c)'

If I do the following it works Product::get((Category*) category ) ... but it should be handled automatically ?

Thanks for your help

high_flyer
3rd December 2010, 14:06
In such cases please state what are the steps you did so far:
header included, namespace resolution, include paths checked etc...

pl01
3rd December 2010, 14:56
Thx,

I have this (There is too much code to put everything !):

"FinancialCategory.hh"


#include "Category.hh"

class FinancialCategory : public Category { ... }


"Product.hh"


namespace Product
{
bool get(Category* c);
}

"Product.cc"


namespace Product
{
bool get(Category* c) { ... }
}


It is very simple code... but can't face where is the problem !!!!

high_flyer
3rd December 2010, 15:21
Yes, but what have you checked so far?
Did you check that you have included the correct header files?
Did you check that the all the paths in your projects are correct?
And all the other stuff you checked so that we don't have to guess if you made all the basic checks first.

Please show the code where you use the statements with more then just the line it self, since most probably the error is in the way you have structured you code.
You don't have to post all the code, but full relevant segments will be most helpful.
The small pieces of code you posted give no information on what you might be doing wrong.


error: undefined reference to `Product::get(FinancialCategory* c)'
Wait a minute...
Do you have a virtual method in your Category class?