Can someone tell me why it dosent work ?!

#include <iostream>
// ad-hoc
int GetSizeOf(int x)
{
	return x;
}
int GetSizeOf(string x)
{
	return x.length();
}
// subtype

class Animals
{
public:
	void MakeSound()
	{
		cout << "heheh sounds go brrrr" << endl;
	}
};
void Stroke(Animals* animals)
{
	
		animals->MakeSound();
}
using namespace std;
int main()
{
	cout << GetSizeOf(5) << endl;
	cout << GetSizeOf("asas") << endl;
	Animals dog;
	Stroke(&dog);

	
}

and also dont judge me about “heheh sounds go brrrr” i wanna sleep

Can I judge you on your use of using namespace std instead? Because that’s your issue; you’re using string without std:: before using using namespace std. If you just fully qualified them you wouldn’t have had this issue.

hmmm … , why then ? tbh i like using std, cause it saves me a lot of time anyways thank u so much Daniel, always judge me lol

For the reasons outlined here
c++ - Why is "using namespace std;" considered bad practice? - Stack Overflow

I think it’s even more important for a beginner to not use it as it helps reinforce what’s where, also as a beginner you’re not well equipped with experience to make such decisions on whether or not it’s “okay” for your particular usage.

I remember starting out using using namespace std and not really knowing what’s part of the language and what is part of the C++ standard library. Now I always full qualify with std::, doesn’t take a lot of time to write out and it’s clearer and saves a potential headache down the line.

now it does make sense for me , Thank u !

1 Like

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

Privacy & Terms