Sending class-reference to method, Error: was not declared in this scope

Hello all. Can you say what is problem?

I have "class Sensor" and all works fine.

In main program I have also this kind of method: void printsensors(Sensor s)

But now it gives error that: "was not declared in this scope".

How can I send class-reference to this method (like other variables)?

My crystal ball is broken, please post your code.
Use CTRL-T in the IDE to auto-format your code, and then paste it between code tags (the </> button on the toolbar).

How can I send class-reference to this method (like other variables)?

The IDE creates function prototypes for you, for functions that use only pass-by-value. When passing a class instance, you are using pass-by-reference, so the IDE can't properly create a function prototype.

The solution is really simple. Create your own function prototypes, like any real C programmer would.

PaulS:
The IDE creates function prototypes for you, for functions that use only pass-by-value. When passing a class instance, you are using pass-by-reference, so the IDE can’t properly create a function prototype.

The solution is really simple. Create your own function prototypes, like any real C programmer would.

So I have to put this function prototype to inside class?

So I have to put this function prototype to inside class?

Is the function a class member? If so, yes. If not, no.

Enable verbose mode when compiling. Find where the cpp file that is created from your ino file is stored. Look at the cpp file. See what the IDE adds to your code, and where.

That is where to put the function prototype.

I give some more information so I maybe get this faster working.

I have made two own classes, one for standart STL-vector and other for Sensor.

This example works:

void loop(){

Vector<Sensor*> sensors;
sensors.push_back(new Sensor (1, 5, "Temperature_1"));

 sensors[s]->reset_search();
   if ( !sensors[s]->search(addr)) {
   //Serial.print("No addresses.\n");
   sensors[s]->reset_search();
   return;
}
}

But when I try use this reference. I have problems to get it working.

Sorry need also this:

printsensors(sensors~~); // ← How should I send it?~~
```
~~void loop(){

Vector<Sensor*> sensors;
  sensors.push_back(new Sensor (1, 5, “Temperature_1”));

printsensors(sensors[s]);
}

void printsensors(Sensor *ds) {

ds->reset_search();
if ( !ds->search(addr)) {
Serial.print(“No more addresses.\n”);
ds->reset_search();
return;
}

}~~
```

But when I try use this reference. I have problems to get it working.

What problems?

It's time to post ALL of your code. The snippets you are posting so far make it look like you don't understand that the sensors are already on a bus, and having a class that does nothing more than wrap a class is pointless.

PaulS:
What problems?

It’s time to post ALL of your code. The snippets you are posting so far make it look like you don’t understand that the sensors are already on a bus, and having a class that does nothing more than wrap a class is pointless.

Those snippets should tell what is the problem.

If u check “this example works”. You can see that it access to right method in Sensor class and it works right. Rest of code is only using those Sensor-class methods when they running in “loop”-method.

sensors[s]->reset_search();

But I have problems to get subprogram doing same thing? It seems pointing to vector class. What is to right way to do this reference send so it uses Sensor class methods?

printsensors(sensors[s])

void printsensors(Sensor *ds)

The question is just that how do I send this same sensors[0] detail to subprogram doing same thing? How to sent reference to printsensors-method or it is better do it in Sensor class and how to use reference for it?

tolerance_zero: Those snippets should tell what is the problem.

SO you are saying that you know what the problem is? Then why are you asking us?

Delta_G:
SO you are saying that you know what the problem is? Then why are you asking us?

I know how I want it working but I dont know how to change it. Your answer was nonsense.

I got it working like this. I m not sure is is the best way but all seems ok.

void loop(){

  Vector<Sensor*> sensors;
  sensors.push_back(new Sensor (1, 5, "Temperature_1"));


  sensors[s]->printsensors(*sensors[s]);
}


Class Sensor{
  void printsensors(Sensor& ds) {
    ds->reset_search();
    if ( !ds->search(addr)) {
    Serial.print("No more addresses.\n");
    ds->reset_search();
    return;
    }
  }

}

It’s not of corse good to use loop-method define those (vector or put information to it) but this was more example how it works.

tolerance_zero: I know how I want it working but I dont know how to change it. Your answer was nonsense.

No

tolerance_zero: Those snippets should tell what is the problem.

This answer is nonsense unless you know what the problem is. How would you know where to find the issue unless you know what the issue is? Others are asking to see the code so they can try to help you find the problem. You only want to show a small portion from which we cannot discern your problem. If you want help, post the code. If you don't want to post the code then we can't really help you.

I got it working like this.

I find that impossible to believe. You are defining that sensors is a Vector of pointers to Sensor instances, but you never define any items to add to that Vector. You you want us to believe that you can then access the non-existent ith element of the Vector and do something useful with it. I refuse to accept that the code works at all.

Delta_G: No

This answer is nonsense unless you know what the problem is. How would you know where to find the issue unless you know what the issue is? Others are asking to see the code so they can try to help you find the problem. You only want to show a small portion from which we cannot discern your problem. If you want help, post the code. If you don't want to post the code then we can't really help you.

You write still nonsense and answer to the topic which you didnt seem understand. The problem was already specified. It not matter if I put 20 class-methods when one is enough. It really change nothing.

PaulS: I find that impossible to believe. You are defining that sensors is a Vector of pointers to Sensor instances, but you never define any items to add to that Vector. You you want us to believe that you can then access the non-existent ith element of the Vector and do something useful with it. I refuse to accept that the code works at all.

I added same thing what was mentioned in #5.