I seem to be having an issue with using multiple class constructors? I did it for one other program and didn't have an issue. I can't seem to find the bug.
Since it is complaining about multiple constructors it won't let me make Plorg1 in the 3rd set of code. Complaining that it doesn't know which constructor to use. Any help is appreciated. Ty
// plorg.h - class declaration for plorg class
#include <cstring>
#include <string>
namespace PLORG
{
class Plorg
{
private:
std::string name;
int index;
public:
Plorg() { name = "Plorga" ; index = 50; }
Plorg(const char * str = "50", const int n = 50);
~Plorg();
void changePlorgCI(const int n);
void showPlorg() const;
};
} // end of namespace
// plorg.cpp - function definitions of plorg class
#include "stdafx.h"
#include "plorg.h"
#include <iostream>
#include <cstring>
namespace PLORG
{
Plorg::Plorg(const char * str, const int n)
{
char temp[19];
strncpy_s(temp, str, 19);
temp[19] = '\0';
name = temp;
index = n;
}
Plorg::~Plorg()
{
std::cout << "Deconstructor Called!" << std::endl;
}
void Plorg::changePlorgCI(const int n)
{
index = n;
}
void Plorg::showPlorg() const
{
std::cout << "Name is " << name << std::endl;
std::cout << "Index is " << index << std::endl;
}
} // end of PLORG namespace
// Exc_7.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "plorg.h"
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
PLORG::Plorg Plorg1;
PLORG::Plorg Plorg2("Testing Plorg 2 cut off", 30);
PLORG::Plorg Plorg3("Testing 3");
Plorg2.showPlorg();
Plorg3.showPlorg();
Plorg3.changePlorgCI(20);
Plorg1.changePlorgCI(30);
Plorg1.showPlorg();
Plorg2.showPlorg();
Plorg3.showPlorg();
system("PAUSE");
return 0;
}