inaccessible constructor

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)
{

m_col=iColumnNum;
m_row= iRowNum;
m_str_val=strValue;
m_double_val=val;
m_cCellType=cCellType;

}
//copy construcor
CCellDescr(const CCellDescr& obj)
{
m_cCellType=obj. m_cCellType;
m_col=obj. m_col;
m_row=obj.m_row;
m_str_val=obj. m_str_val;
m_double_val=obj.m_double_val;
}

double getvalue()const

{
return m_double_val;
}

string getValue()const
{
return m_str_val;

}

int getrow()const
{
return m_row;


}

int getcol()const
{
return m_col;


}

char getType()const
{
return m_cCellType;

}

void setvalue( const double& val)
{
m_double_val=val;

}

void setValue(const string& strValue)
{
m_str_val=strValue;


}

void setrow(const int& row)
{
m_row=row;


}

void setcol(const int& col)
{
m_col=col;


}
void setcelltype(const int& type)
{
m_cCellType=type;

}

void Output(ostream& toStream)
{

toStream<<m_double_val<<m_str_val<<m_row<<m_col<< m_cCellType;

}

friend ostream& operator<<(ostream& toStream,CCellDescr& obj)

{
obj.Output(toStream);
return toStream;

}

};

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;

}

~CData()//destructor
{}

int getcolumns()const
{
return m_iColumns;

}

int getrows()const
{
return m_iRows;

}

void setCell(const CCellDescr& cell_Data)
{

m_Data=cell_Data;

}


};

void main()
{

CData cell(89,7);
system("pause");
}
Last edited on
Everything in your classes is private: change to public: what you want to be available from 'outside'
your constructor is listed as private you need it to be public
Last edited on
Next time put your code in code tags, to preserve indentation and have syntax highlighting:
[code]const int i = 5; // example [/code]

http://www.cplusplus.com/articles/jEywvCM9/

The problem is that your member functions (including your constructor) are not public:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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; 
};
Topic archived. No new replies allowed.