Hi,everybody!I am trying to make an object in my main function from the class CCellDescr.But the compiler every time gives me the error that the explicit constructor at line 163 is inaccessible.Here`s the code:
#include<iostream>
#include<fstream>
#include<list>
#include<string>
using namespace std;
class CCellDescr
{
double m_double_val;
string m_str_val;
int m_row;
int m_col;
char m_cCellType; // 'N' 'S'
//explicit construcor
CCellDescr(char cCellType, int iColumnNum,int iRowNum,const string strValue,double val)
{
class CData
{
private:
list<CCellDescr*> m_Data; // table content(pointers to a cell)
int m_iColumns; // the number of the valid columns in the table
int m_iRows;
CData(int iColumns, int iRows )
{
m_iColumns=iColumns;
m_iRows=iRows;
class Example
{
// private by default
int a;
void func_a() {}
private:
int b;
void func_b() {}
public:
int c;
void func_c() {}
};
int main() // never void main() in C or C++
{
Example e;
e.func_a(); // compilation error
e.func_b(); // compilation error
e.func_c(); // works
}
Because, you have declared everything within you 'CData' class as 'Private'. I normally declare my classes 'Public' accessors first followed by 'Protected' (if required) and finally 'Private'. So, I would declare your CData class as follows:
class CData
{
public:
CData(int iColumns, int iRows )
{
m_iColumns=iColumns;
m_iRows=iRows;
}
~CData()//destructor
{}
int getcolumns()const
{
return m_iColumns;
}
int getrows()const
{
return m_iRows;
}
void setCell(const CCellDescr& cell_Data)
{
m_Data = cell_Data;
}
private:
list<CCellDescr*> m_Data; // table content(pointers to a cell)
int m_iColumns; // the number of the valid columns in the table
int m_iRows;
};