c++ - Can't acces private members in a object of same type -


the problem in title, here's code:

#include <iostream> #include <cstring>  using namespace std;  template<typename t1, typename t2> class pair {     t1 first;     t2 second;   public:     pair(t1 _first = null, t2 _second = null) : first(_first), second(_second) {}     pair(const pair<t1, t2>&  other) : first(other.first),  second(other.second) {} };  template<> class pair<char*, char*> {     char* first;     char* second; public:      pair(char* _first = null, char* _second = null) : first(_strdup(_first)), second(_strdup(_second)) {}      pair(const pair<char*, char*>& other) : first(_strdup(other.first)),  second(_strdup(other.second)) {} };  int main() {     pair<short, char> pair;     pair<char*, char*> pair2; } 

5 intellisense: member "pair::first" (declared @ line 20) inaccessible
6 intellisense: member "pair::second" (declared @ line 21) inaccessible

so what, exclusive template classes pointers data members, objects of same class can't access them? , solution? i've tried creating member functions(before constructor) return these pointers, , use them, i've got other error.

not sure may question duplicate, there question similar title didn't understand answer...

don't advise use std::string instead of char*, if ;)

the code fine, intellisense wrong.

although may want consider fact not types can initialized null. if want default constructor, use pair() = default;.


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -