1 // { dg-do assemble } 2 // GROUPS passed visibility 3 // visibility file 4 // From: Sandeep Shroff <ss@caere.com> 5 // Date: Thu, 05 Aug 1993 17:23:20 -0700 6 // Subject: Access to private constructor. 7 // Message-ID: <9308060023.AA10283@neptune.caere.com> 8 #include <iostream> 9 #include <cstring> 10 11 class Base 12 { 13 public: getName()14 char* getName() {return name_;} 15 16 private: 17 Base(); 18 Base(char* str); 19 20 char* name_; 21 }; 22 23 class Derived : public Base 24 { 25 public: 26 Derived(int n, char* str); 27 Derived(int n); 28 getNum()29 int getNum() {return num_;} 30 private: 31 int num_; 32 }; 33 Base()34Base::Base() // { dg-message "private" } 35 { 36 name_ = std::strcpy(new char[std::strlen(" ") + 1], " "); 37 } 38 Base(char * str)39Base::Base(char* str) // { dg-message "private" } 40 { 41 if(str != NULL) 42 name_ = std::strcpy(new char[std::strlen(str) + 1], str); 43 } 44 Derived(int n,char * str)45Derived::Derived(int n, char* str) : Base(str) // { dg-error "within this context" } 46 { 47 num_ = n; 48 } 49 Derived(int n)50Derived::Derived(int n) : Base() // { dg-error "within this context" } 51 { 52 num_ = n; 53 } 54 55 56 main()57int main() 58 { 59 // Derived* d = new Derived(10, "test"); 60 Derived* d = new Derived(10); 61 62 std::cerr << d->getNum() << "\t" << d->getName() << std::endl; 63 } 64 65 66 67