Note: I'm using Visual Studio 2010.
There are two important classes here, Date and Directory.
class Date
{
private:
int month, day, year;
public:
Date();
Date(int month, int day, int year);
};
class Directory : public [Superclass]
{
private:
File* fileContents[50];
Directory* dirContents[5];
public:
Directory();
Directory(char* name,
long size,
Date dateCreated,
Date dateModified,
Date dateAccessed,
int attributes);
};
I defined the constructors farther down - the Date constructor works just like you think it does. Now, I'm really new to C++, so I can't even comprehend the error messages I'm getting. If I try to use the default constructor for Directory, I get this error message:
error LNK2019: unresolved external symbol "class Directory __cdecl d(void)" (?d@@YA?AVDirectory@@XZ) referenced in function _main
If I try to make it by using 3 Date objects, with this code:
int main()
{
Date d1();
Date d2();
Date d3();
Directory d("Hello", 12, d1, d2, d3, 0);
cout << d;
}
These are my error messages:
error C2664: 'Directory::Directory(char *,long,Date,Date,Date,int)' : cannot convert parameter 3 from 'Date (__cdecl *)(void)' to 'Date'
IntelliSense: no instance of constructor "Directory::Directory" matches the argument list
EDIT: So, in a continuing effort to make zero sense to me, VS has decided to compile my program fine when the three Date arguments are created with Date da[3] and the arguments for the constructor are ("Hello", 12, d[0], d[1], d[2], 0).
According to the standard
An object whose initializer is an empty set of parentheses, i.e., (), shall be value-initialized.
[Note: since () is not permitted by the syntax for initializer,
X a ();
is not the declaration of an object of class X, but the declaration of a function taking no argument and returning an X. The form () is permitted in certain other initialization contexts (5.3.4, 5.2.3, 12.6.2). —end note ]
So, you need to change your declarations as follows
int main()
{
Date d1;
Date d2;
Date d3;
Directory d("Hello", 12, d1, d2, d3, 0);
cout << d;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With