Can someone help me with this?

class Note{
private:
double Freq;
int milisec;
public:
Note();
Note(double Fr, int ms){
Freq = Fr;
milisec = ms;
};
~Note();
};


Ok... now I declare something like this:

Note mynotes[MAX_NOTES];

is there a way to find out the array size?

Thanks

Recommended Answers

All 4 Replies

>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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.