Array of structs: no matching function for call

Hi,
I have been trying to figure out what is wrong with this code. All I want is an array of structures. But the compiler tells me
functions.cpp:54: error: no matching function for call to `Visits::Visits()'
. I initialized the records, still the same error. I am able to do it in C but as soon as I go to C++ it does not like it. Maybe someone knows why.
Thank you!

1
2
3
4
5
6
7
  struct Visits{
	char IP[IP_MAX_CHAR];
	char link[LINK_MAX_CHAR];
	Date d;
};

struct Visits records[MAX_ENTRIES];
how is Date defined?
class Date {

public:
Date::Date(int mn, int dy, int yr);
int Date::getDay();
int Date::getMonth();
int Date::getYear();
bool Date::checkDate();
void Date::setDay(int d);
void Date::setMonth(int m);
void Date::setYear(int y);

private:
int month;
int day;
int year;
int checkDay(int);
int checkMonth(int);
int checkYear(int);
};
Your Date class has no default constructor, and since it is a member of your Visits class, Visits is not allowed to have a default constructor either. You should create a default constructor for your Visits class that initializes d correctly, or provide a default constructor for your Date class.
You showed irrelevant code.
it looks like the compiler does not see the defiition of structure Visits, So it think hat in the statement

struct Visits records[MAX_ENTRIES];

you are declaring a new structure in the given declarative region.
Last edited on
@vlad the code he showed was relevant and I explained the problem.

Also, that statement does not declare a new structure - it works like in C. The error would be something about incomplete types if the structure was not previously defined.
Last edited on
OMG! Thank you so much! I have been trying to debug this for 6 hours now... I never know what the error messages in C++ are.....
@L B
@vlad the code he showed was relevant and I explained the problem.

Also, that statement does not declare a new structure - it works like in C. The error would be something about incomplete types if the structure was not previously defined


Whan I was writing my post I did not see yet the second his post with the definition of class Date

As for your second statement then for example this declaration declares a new structure

struct NewStruct *pl

Last edited on
vlad from moscow wrote:
Whan I was writing my post I did not see yet the second his post with the definition of class Date
Sorry then - timing on forums is always a bit frustrating.
vlad from moscow wrote:
As for your second statement then for example this declaration declares a new structure

struct NewStruct *pl
Yes, but that is because with pointers and incomplete type it allowed. I don't think it's allowed for arrays, though I don't know for sure.
Last edited on

@lousigirl
OMG! Thank you so much! I have been trying to debug this for 6 hours now... I never know what the error messages in C++ are.....


It is very interesting how you have been trying to debug the code if it is not compiled..
Last edited on

@L B
Yes, but that is because with pointers and incomplete type it allowed. I don't think it's allowed for arrays, though I don't know for sure.


So I thought that as the compiler did not see the structure definition it issued the error.
Topic archived. No new replies allowed.