Can someone help me with this?

class Note{
double Freq;
int milisec;
Note(double Fr, int ms){
Freq = Fr;
milisec = ms;

Ok... now I declare something like this:

Note mynotes[MAX_NOTES];

is there a way to find out the array size?


9 Years
Discussion Span
Last Post by vijayan121

>is there a way to find out the array size?
Depends where you need to find such a length.

If the array is in fact being held by a pointer, then no, there isn't a way to figure out the size of an array, because there's boundaries as it's a pointer.

If it is a real array however, you can use the sizeof operator to calculate it by dividing the total amount of memory taken by the array by the size of an element.

#include <iostream>
using namespace std;

int main() {
	int array[10] = {0};
	cout << "Array size is " << sizeof array / sizeof *array << ". " 
             << endl;

But then again, why do you need to calculate it anyway? If must have known at some point what the array dimensions were, and surely you can save that number...


Is there a way to return the values of a Note?

I mean something like:

Note Note::getNote(){
return //Note values Freq and milisec


>Is there a way to return the values of a Note?
Try creating separate accessor functions, as you cannot return more than one value from a function. Something like getFreq , getMillisec , etc..


there are two ways to simulate returning
many values from a function:
a. return a struct with more than one
member variable. std :: pair<> is handy
if you want to return a pair of values.
b. pass a modifiable referance (or pointer
to non const) as a parameter, which
the function can fill up.
if the types of all the values returned are
the same, u could also return a collection;
eg: std::vector

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.