Namespace

Untitled1.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>

namespace mynames {
 class string;         
};

class string {
 public:
 char s[50];
 string operator= (const char*);      
};

string string :: operator= (const char* sorgente)
{      
 strcpy(s, sorgente); 
 return *this; 
}


Untitled2.cpp
1
2
3
4
5
6
7
8
9
#include "Untitled1.h"
using namespace mynames;

int main() {
 
 string s1;
 
 system("pause");   
}


Error:
'string' undeclared.

I want to try my class string, not std :: string!
Last edited on
You have a forward declaration for class mynames::string inside the namespace. Just pepper some of mynames:: like this:
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
#include <iostream>
#include <cstring>

namespace mynames
{
	class string;
};

class mynames::string
{
public:
 	char s[50];
 	mynames::string operator= (const char* sorgente);
};

mynames::string mynames::string::operator= (const char* sorgente)
{
 	strcpy(s, sorgente);
 	return *this;
}

using namespace mynames;

int main()
{
	string s1;
	return 0;
}


Also you forgot to include cstring for strcpy(s, sorgente); and cstdlib for system("pause");
thanks! kevin!
Topic archived. No new replies allowed.