Home » Class has no member speak? [closed]

Class has no member speak? [closed]

Solutons:


void::speak(); //THE GLOBAL SCOPE HAS NO SPEAK

It’s interpreting this as void ::speak() where leading an identifier (a name) with :: indicates to C++, “Look in the global scope of all names”. :: is the “scope resolution operator”

In the header file, you should just use void speak(); since C++ sees it inside your class declaration and hence knows it’s part of the class.

How did it even try to compile this line: void::speak();?
What did you even mean by it? Method speak() inside void namespace? but void is a reserved typename. Moreover, why is it inside the class then?

As I can guess, you were trying to use void speak(); instead.

void::speak()

I figured I would chime in on this answer. But the above line is your problem. Essentially, what you have asked the program to do is look in the scope of the void namespace. However, void is a reserved typename and to my knowledge, does not have a function named speak() in it.

This is the one of the problems with using namespace std. Usually, when you are using something from the standard library, take string for example, you will say, “I need to declare a string here, from the standard library. std::string hello, is a perfectly good example that states, “string belongs in the standard libraries scope.” using namespace std is bad practice and you go fumbling around trying things like void::speak() which again, is asking to grab it from void’s namespace.

That being said, in classes, the header file is commonly used to declare functions in which you will use later. In the cpp file, you are simply saying, I have a class Cat and from the scope of Cat I will be using the function speak(). So speak() belongs to the class Cat and is in the scope of Cat. Which is why in the cpp file, you call void Cat::speak();

So in summary, you header file should be:

class Cat
{
  public:
    void speak(); // the class has a public function named speak.
};

Related Solutions

StringBuilder delete methods [closed]

I'd say this is fine. The intent is different. Lets try this for example: String builder sb = new StringBuilder(); sb.append("hello").append("hello"); sb.delete(0,5); sb.toString(); It prints "hello". Had you read the documentation, you'd see that the end is...

How to get specific element from array of type any in swift?

You should not be using JSONSerializer in Swift. A better option is a JSONDecoder. JSONDecoder will allow you to establish and preserve the type information for the data you've decoded. Here is an Playground example of how you would use JSONDecoder to handle...

How to make RecyclerView behave like Paragraph?

The answer is FlexBoxLayoutManager you can use it with RecyclerView put implementation 'com.google.android:flexbox:1.0.0' in your gradle file. Now setting up RecyclerView layout, <?xml version="1.0" encoding="utf-8"?> <RelativeLayout...

Piping commands after a piped xargs

You are almost there. In your last command, you can use -I to do the ls correctly -I replace-str Replace occurrences of replace-str in the initial-arguments with names read from standard input.  Also, unquoted blanks do not terminate input items; instead the...

create arrow using css

Try to use Font awsome LINK HTML: <i class="fa fa-arrow-right"></i> fa-arrow-right Yes, there are several ways of doing this. 1. With an image First of all, in order to do what you've suggested, you can indeed use an image - but instead of coloring...

accessing values structure within structure? [closed]

Just create an object of emp1 inside your main, and give it a value like below and it should be ok emp1 emp; emp.number.number1=3; //printf then with emp.number.number1 😉 You are accessing the value "number1" like emp1.number.number1 but here "emp" data type...

What’s wrong with this way to add rows to dataframe?

Try: data <- data.frame(A= character(0), B= character(0), stringsAsFactors=FALSE) data[1, ] <- c("AA", "BB") In your example, A and B are factors. I would suggest a different approach from the other answers. If A and B are something like names or ID...

Panagram python code [closed]

import string def isPanagram(sentence): alphabet = string.lowercase[:26] # list of letters a-z return all(letter in sentence.lower() for letter in alphabet) The function all will return true if all elements in a list are true The list comprehension inside goes...

VB Code explanation? [closed]

Declare a student name variable that we will call studentname as a string. Think of variables as you would do x and y in an algebraic equation. They are simply names for things of a particular type. In a maths equation x and y are numbers. A string is a...

remove null items from a multidimensional array in C#

Are your null objects always at the end of the multidimentional array? If so use something like this to remove the null items: private static void ReDimMultiObjects(ref object[,] arr, int length) { object[,] arrTemp = new object[length, 3];//New number of...

Check if string contains only one type of letter C# [closed]

Try this: private bool ContainsOnlyOneLetter(string String) { if(String.Length == 0) { return true; } for(int i = 0; i < String.Length;i++) { if(String.Substring(i,1) != String.Substring(0,1)) { return false; } } return true; } And you can use the function...

Couldn’t understand this SWIFT Fucntion [closed]

You're getting 120 because you're asking the tuple for the sum value twice. The tuple passed back is (min: Int, max: Int, sum: Int). In this case, sum is also index number 2 (min is index zero, max is index one). So in this case statistics.sum == statistics.2...

C++ Cli code stucked [closed]

The code you provided does not work on any numbers. The only thing it does is construct some SQL query check its result During the SQL-query-construction, the code does not assume any "numbers" to be provided. It actually uses a variable called...