Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

request for member which is of non-class type

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!

Update

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
like image 878
sniperu Avatar asked May 03 '13 16:05

sniperu


2 Answers

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).

like image 138
Andy Prowl Avatar answered Oct 07 '22 02:10

Andy Prowl


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.

like image 33
john Avatar answered Oct 07 '22 02:10

john