No matching function or call, but there is?

So I've been working on this little project and while refactoring some code I went into this issue. So I have this class calles PageComponent which is defined in the .h file and even in the .cpp file, the .h file compiles without any issue but the .cpp file gives error whenever I try to use PageComponent as argument, even tho it is declarated and it works in the .h file.

Here are some screenshots:

Page::Page(String Title, PageComponent PageComponents[5]) {
  Name = Title;
  Components = PageComponents;
}

Error Picture

If someone is able to help, thanks alot!

please, please never ever again post pictures of text... Not only they are not readable nor usable directly for copy&paste but they use up lots of storage and internet bandwidth which contributes to polluting the planet.

➜ do your part and do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

Seems you should refresh : <initializerList> syntax of constructors.

https://www.learncpp.com/cpp-tutorial/constructor-member-initializer-lists/

What do you mean by refresh? Im kinda new to coding in C++ so I don't understand all of this terms, sorry.

so then it's not a refresher, it's learning about

(he meant a course refresher I suppose)

PS: please fix post 1. Edit it and Post the text and code within code tags...

I tried changing it like the article suggests.

Here's how the constructor looks now:

.cpp File

PageComponent::PageComponent(String ComponentType, String CMem): Type{ComponentType}, Memory{CMem} {
}

.h File

class PageComponent {
  public:
    String Type;
    String Memory;
    PageComponent(String ComponentType, String CMem);
};

But I still get the same exact error:

Compilation error: no matching function for call to 'PageComponent::PageComponent()'

see this example

(your updated code is in the two tabs)

(passing Strings by copy is not memory efficient)

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.