if i declare an array without mentioning its size on visual studio code or other online compiler then it works fine but if i use same code in visual studio then it does not work. i know its not correct to declare unknown size array but just due to condition of not using pointer or any other thing, i had to use it. On visual studio, when i made only link and webpage class then i worked.
Can anyone tell me how to do this.
#include <iostream>
using namespace std;
class link
{
const char* name;
public:
link() :name("null")
{
cout<<"Default link constructor called"<<endl;
};
link(const char n[]) :name(n)
{
cout<< "Parameterized link constructor called"<<endl;
};
};
class webpage
{
private:
double height;
double width;
int linkno;
link links[];
public:
webpage() :height(10), width(10), linkno(2)
{
links[0]=NULL;
links[1]=NULL;
};
webpage(double hw,int lno, link hyperlinks[]) :height(hw), width(hw),linkno(lno)
{
for (int i = 0; i < linkno; i++)
{
links[i]=hyperlinks[i];
}
};
webpage(double h, double w,int lno, link hyperlinks[]) :height(h), width(w),linkno(lno)
{
for (int i = 0; i < linkno; i++)
{
links[i]=hyperlinks[i];
}
};
void showdata(int linkno)
{
cout << "height: " << height << endl;
cout << "width: " << width << endl;
cout << "links " << endl;
for (int i = 0; i < linkno; i++)
{
cout << "link #" << i + 1 << " = " << links[i].getname() << endl;
}
}
};
class website
{
private:
const char* name;
int webpageno;
webpage wpgs[];
public:
website() :name("null"),webpageno(4)
{
wpgs[0];
wpgs[1];
wpgs[2];
wpgs[3];
};
website(const char n[],int wpn, webpage page[]) :name(n),webpageno(wpn)
{
for (int i = 0; i < webpageno; i++)
{
wpgs[i]=page[i];
}
cout<<"Parameterized website constructor called"<<endl;
};
void showdata(int linkno, int pageno)
{
cout << endl<< "Website name: " << name << endl;
for (int j = 0; j < pageno; j++)
{
cout << "Webpage #" << j + 1 << " : " << endl;
wpgs[j].showdata(linkno);
cout<<endl<<endl;
}
}
};
int main(int argc, char* argv[])
{
link link1[2]={"maha","saira"};
webpage page[1]={{32,21,2,link1}};
website site("my website",1,page);
site.showdata(2,1);
}
On visual studio, when i made only link and webpage class then i worked.
link * links = nullptr; links = new links[2048];wpgs[#];statements) also does nothing at all.std::vector. Example:std::vector<link> links;links.push_back(hyperlinks[i]);cthatc++does not have: https://en.wikipedia.org/wiki/Flexible_array_member