-
What is the output of this program?
#include <iostream>
#include <vector>
#include <iterator>
#include <stddef.h>
using namespace std;
template<class myType>
class Container
{
public:
Container(size_t xDim, size_t yDim, myType const& defaultValue)
: objData(xDim * yDim, defaultValue)
, xSize(xDim)
, ySize(yDim)
{
}
myType& operator()(size_t x, size_t y)
{
return objData[y * xSize + x];
}
myType const& operator()(size_t x, size_t y) const
{
return objData[y * xSize + x];
}
int getSize()
{
return objData.size();
}
void inputEntireVector(vector<myType> inputVector)
{
objData.swap(inputVector);
}
void printContainer(ostream& stream)
{
copy(objData.begin(), objData.end(),
ostream_iterator<myType>(stream, ""/*No Space*/));
}
private:
vector<myType> objData;
size_t xSize;
size_t ySize;
};
template<class myType>
inline ostream& operator<<(ostream& stream, Container<myType>& object)
{
object.printContainer(stream);
return stream;
}
void ContainerInterfacing();
int main()
{
ContainerInterfacing();
return 0;
}
void ContainerInterfacing()
{
static int const ConsoleWidth = 95;
static int const ConsoleHeight = 30;
size_t width = ConsoleWidth;
size_t height = ConsoleHeight;
Container<int> mySimpleContainer(width, height, 0);
cout << mySimpleContainer.getSize() << endl;
mySimpleContainer(0, 0) = 4;
}
-
- 2850
- No Space
- Depends on the compiler
- Compilation Error
- None of these
Correct Option: C
In this program, We formed a simple container and got the size of it and printing it.