0

I created a class called Text, and one of its members is a std::vector of Pal_freq, a struct declared inside the class.

I am getting those errors:

error: ‘Pal_freq’ does not name a type bool criteri (const Pal_freq& p1, const Pal_freq& p2);

error: ‘Pal_freq’ does not name a type bool criteri (const Pal_freq& p1, const Pal_freq& p2);

error: ‘Pal_freq’ was not declared in this scope vector consultar_taula_freq();

error: template argument 1 is invalid vector consultar_taula_freq();

Here is the code:

class Text {
 public:

  struct Pal_freq {
  int freq;
  string pal;
  };

  vector <Pal_freq> taula;
};
7
  • 2
    Works here. Did you forget to #include <string> or #include <vector>? Commented May 18, 2016 at 10:00
  • 6
    Hello Pau, to get better help you should include the error message. "Doesn't work" is not very telling. Commented May 18, 2016 at 10:01
  • 2
    your error messages do not correlate with your code Commented May 18, 2016 at 10:08
  • 3
    You are clearly not including the whole code. My guess is you aren't qualifying the name Text::Pal_freq when you use it outside of Text. Commented May 18, 2016 at 10:08
  • 2
    @Pau, I didn't say you should include the whole class, please read my comment again! Read the link on how to create a minimal and complete example. That doesn't just mean dump the entire piece of code here. Read the links and the guides on how to use this site, it will save you time and save us time, so you get better answers (but in this case I already gave you the answer below ... but please read how to use this site properly!) Commented May 18, 2016 at 10:13

1 Answer 1

3

The error messages are not coming from the tiny piece of ode you showed (the definition of the struct), they are coming from other pieces of code that you didn't show us (i.e. where you try to use the nested struct).

Because it is declared inside Text you need to qualify its name when you refer to it outside the scope of Text, so you need to refer to it as Text::Pal_freq e.g.

bool criteri (const Text::Pal_freq& p1, const Text::Pal_freq& p2);

Please read the "how to ask" guidelines on the site, and make sure you include all the necessary code for us to help you.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you! bool criteri is inside Text, should I use Text:: anyway?
"bool criteri is inside Text" No it isn't. Not in the code you showed us. This is why we can't help you unless you ask better questions. How do you expect people to explain why you get errors for criteri if you don't show criteri?! Maybe you need to move the declaration of Pal_freq before the member functions that try to use it. But show the code, or we're just guessing, and your question should be closed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.