C++ Visual Studio overloaded function error: no instance of overloaded function matches the specified type
C++ Visual Studio overloaded function error: no instance of overloaded function matches the specified type
CLARIFICATION:
This project is being done in Visual Studio, with an stdafx.h file used.
FText is an alias for string, as established in the file stdafx.h:
#include <string>
using FText = std::string;
using int32 = int;
stdafx.h is included in the View.cpp class.
ORIGINAL QUESTION:
So, I am trying to create several print methods which print a string based on one or two parameters: a number parameter that indicates which message to print, and an input to be used in the message. As of now, I have three instances of the method "print", as shown below:
///A method that prints a message
//give it a number to tell it what message to print.
void Display::print(int message)
{
switch (message)
{
case 0:
std::cout << "Welcome to Cows and Bulls, a simple word-guessing game. n";
break;
case 1:
//(I omitted most of the messages to save space)
break;
default:
std::cout << "Something has gone horribly wrong. n";
std::cout << "Goodbye. n";
throw std::exception();
}
}
//messages with one int parameter
void Display::print(int message, int param)
{
switch (message)
{
case 0:
break;
default:
std::cout << "Something has gone horribly wrong. n";
std::cout << "Goodbye. n";
throw std::exception();
}
}
//messages with one string parameter
void Display::print(int message, FText param)
{
switch (message)
{
case 0:
break;
default:
std::cout << "Something has gone horribly wrong. n";
std::cout << "Goodbye. n";
throw std::exception();
}
}
I haven't added any messages to the second and third overload yet, but I'll get to that.
The class declaration in the header file for the view part of the program looks like this:
#pragma once
//The method that prints thing to the screen
class Display
{
public:
void print(int message);
//print a message with a parameter other than the message being selected
void print(int message, int param);
void print(int message, FText param);
};
The first two instances of the print method work fine, but the third one (the one with a string/FText as a parameter) is giving me the following error:
"no instance of overloaded function "CowsAndBulls::Display::print" matches the specified type"
To add a little extra clarity, the code still compiles, and I have not used this function yet: I'm getting an error in the definition of this version of print.
I'm fairly certain I'm just missing something simple, but a quick search through stack overflow's questions has failed to bring me another problem with exactly the same circumstances as this (or perhaps I just failed to recognize another post as the same problem?)
either way, any assistance is appreciated.
FText
I'm fairly certain this has something to do with the organization of your program, such as, as lisyarus said, where
FText
is defined or where various files are included.– Silvio Mayolo
Jul 1 at 15:46
FText
Sorry, I should have made that clear. FText is just an alias for string, which I put in to uphold Unreal's coding standards (at least a little.) I'll add it to the question.
– Globin347
Jul 1 at 15:48
Googling tells me that
FText
is a string-type in Unreal engine, correct? Can you provide more info. Because if I replace FText
with a simple std::string
I don't have any problems compiling or running your code.– rbaleksandar
Jul 1 at 15:48
FText
FText
std::string
How does your compiler know what
FText
is? I don't know anything about UE development environment but maybe you're missing a header include? Runtime/Core/Public/Internationalization/Text.h
is referenced in the api doc– Fluffy
Jul 1 at 15:50
FText
Runtime/Core/Public/Internationalization/Text.h
1 Answer
1
Ok, looks like I forgot to include stdafx.h in the View class header file. While stdafx.h (and by extension, FText) was included in the cpp file, the header file apparently didn't know what it was. This was throwing me off, because the error was displayed in the cpp file.
For future reference, does anyone know why that is?
Next time mention which OS and tools you are working with.
stdafx.h
is a Microsoft and in particular Visual Studio gimmick. You can read on why and what it is used for here.– rbaleksandar
Jul 1 at 15:57
stdafx.h
Gotcha. I guess it's hard to tell what will be relevant. I'll add Visual Studio to the question tags.
– Globin347
Jul 1 at 15:58
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
What is
FText
? Where is it defined?– lisyarus
Jul 1 at 15:45