M
mrkafk
Hello everyone,
I'm very much (greenish) new to C++, learning it with S. Lippman's "C+
+ Primer" in hand.
I tried to extend one example:
#include <iostream>
using namespace std;
class IntArray
{
public:
explicit IntArray(int sz = DefaultArraySize);
IntArray(int *array, int array_size);
int siz();
private:
static const int DefaultArraySize = 12;
int _size;
int* ia;
};
IntArray::IntArray(int sz)
{
_size = sz;
ia = new int[_size];
for (int i=0; i<_size; i++)
ia=0;
}
IntArray::siz()
{
return _size;
}
int main()
{
IntArray a(5);
cout << "a.siz() : " << a.siz() << endl;
}
Yet, g++ complains:
e.C:25: error: ISO C++ forbids declaration of 'siz' with no type
? I don't get it? After all, I have declared siz() to be of int type
in the class declaration? I can't use IntArray::int siz(), can I?
(of course I tried it and get e.C:25: error: expected unqualified-id
before 'int' instead, doomed if I do and doomed if I don't)
I'm very much (greenish) new to C++, learning it with S. Lippman's "C+
+ Primer" in hand.
I tried to extend one example:
#include <iostream>
using namespace std;
class IntArray
{
public:
explicit IntArray(int sz = DefaultArraySize);
IntArray(int *array, int array_size);
int siz();
private:
static const int DefaultArraySize = 12;
int _size;
int* ia;
};
IntArray::IntArray(int sz)
{
_size = sz;
ia = new int[_size];
for (int i=0; i<_size; i++)
ia=0;
}
IntArray::siz()
{
return _size;
}
int main()
{
IntArray a(5);
cout << "a.siz() : " << a.siz() << endl;
}
Yet, g++ complains:
e.C:25: error: ISO C++ forbids declaration of 'siz' with no type
? I don't get it? After all, I have declared siz() to be of int type
in the class declaration? I can't use IntArray::int siz(), can I?
(of course I tried it and get e.C:25: error: expected unqualified-id
before 'int' instead, doomed if I do and doomed if I don't)