i got this error and i am not able to solve by myself
source.cpp:85:8: error: request for member ‘put_tag’ in ‘aux’, which is of non-class type ‘Keyword()’
source.cpp:86:8: error: request for member ‘put_site’ in ‘aux’, which is of non-class type ‘Keyword()’
make: *** [source.o] Error 1
the code which gives me this error is
Keyword aux();
aux.put_tag(word);
aux.put_site(site);
I must mention that word and site are char *
type
Now, my Keyword class definition is this one:
class Keyword{
private:
std::string tag;
Stack<std::string> weblist;
public:
Keyword();
~Keyword();
void put_tag(std::string word)
{
tag = word;
}
void put_site(std::string site)
{
weblist.push(site);
}
};
Thank you very much!
By modifying
Keyword aux();
aux.put_tag(word);
aux.put_site(site);
in
Keyword aux;
aux.put_tag(word);
aux.put_site(site);
i got this error:
source.o: In function `Algorithm::indexSite(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
source.cpp:(.text+0x2c6): undefined reference to `Keyword::Keyword()'
source.cpp:(.text+0x369): undefined reference to `Keyword::~Keyword()'
source.cpp:(.text+0x4a8): undefined reference to `Keyword::~Keyword()'
source.o: In function `Keyword::put_site(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
source.cpp:(.text._ZN7Keyword8put_siteESs[Keyword::put_site(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)]+0x2a): undefined reference to `Stack<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::push(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
collect2: ld returned 1 exit status
make: *** [tema3] Error 1
This line does not do what you think:
Keyword aux();
Is declaring a function called aux
that takes no arguments and returns a Keyword
. You most likely meant to write (without the parentheses):
Keyword aux;
Which declares an object of type Keyword
.
UPDATE:
Concerning the next error you are getting, this is because you have a declaration of the constructor and destructor of your class, but not a definition. In fact, the error you are getting comes from the linker, and not from the compiler.
To provide a trivial definition of your constructor and destructor, change this:
Keyword();
~Keyword();
Into this:
Keyword() { }
~Keyword() { }
Or, as long as these member functions do nothing, just omit them at all - the compiler will generate them for you (unless you add some other user-declared constructor, for what concerns the constructor).
Not this
Keyword aux();
aux.put_tag(word);
aux.put_site(site);
but this
Keyword aux;
aux.put_tag(word);
aux.put_site(site);
In your version Keyword aux();
is a function prototype not a variable declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With