Error while making DLL

Pages: 12
I have same problem with win32 API, all the time I'm doing a gui application I forget to set it's window class, and then I wonder why nothing is working and why I cant even close the window (^_^)
Well by sheer probability I imagine even the pros must make newbish mistakes from time to time.
just one more question, I hope you will still read this:

when making a class, and I want to call another class function within a class function, do I have to use Class name, or just function? (instanced)

e.g.:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class myclass
{
	public:
	void Function1();
	int Function2();
};

void myclass::Function1()
{
	myclass::Function2();
}

int myclass::Function2()
{
	return 1;
}


OR

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class myclass
{
	public:
	void Function1();
	int Function2();
};

void myclass::Function1()
{
	Function2();
}

int myclass::Function2()
{
	return 1;
}


which one should I use, when I want to call function 2 with a instanced class, like this

1
2
3
4
5
int main()
{
	myclass a;
	a.Function1();
}


I want "a" to call a Function2 (from function 1), not to call Function2 as from class, I hope u understand :D

like, I want to run the function within the instance of that class, not in class by default

e.g. I want to call function Function2 from A, so the code should work like this
a.Function2();

and NOT like this

myclass::Function2();

so should I use the CLASSNAME:: in the function within the function, or just call the function?
Last edited on
When inside any namespace (including class namespaces) you just need to call the function. If it's running from an instance then it'll call on it's own instance.

The only time you need to explicitly add a namespace is if you have the same function name inside your current namespace and you want to use an outer namespace:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace one{
    void func(){
        return;
    }
}//namespace

namespace two{
    void func(){
        one::func();
        return;
    }
}// namespace

void main(){
    two::func();
    return;
}
so when I use a code like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class myclass
{
	public:
	void Function1();
	int Function2();
};

void myclass::Function1()
{
	Function2();
}

int myclass::Function2()
{
	return 1;
}


It will call Function2 of a specific instance, for example when I do

1
2
myclass a;
a.Function1();

it will call Function2 of a "a" class instance, right? also what if I WILL include the class name, so

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class myclass
{
	public:
	void Function1();
	int Function2();
};

void myclass::Function1()
{
	myclass::Function2();
}

int myclass::Function2()
{
	return 1;
}

will this change anything, or will it work just as the first example?

ALSO I can't somehow manage to get class into the namespace, since it gives me bunch of errors:

1>PathSocket.cpp(3): error C2062: type 'int' unexpected
1>PathSocket.cpp(4): error C2143: syntax error : missing ';' before '{'
1>PathSocket.cpp(4): error C2447: '{' : missing function header (old-style formal list?)
1>PathSocket.cpp(12): error C2062: type 'int' unexpected
1>PathSocket.cpp(13): error C2143: syntax error : missing ';' before '{'
1>PathSocket.cpp(13): error C2447: '{' : missing function header (old-style formal list?)
1>PathSocket.cpp(32): error C2588: '::~PathSocket' : illegal global destructor
1>PathSocket.cpp(32): fatal error C1903: unable to recover from previous error(s); stopping compilation


header: http://pastebin.com/504MgTpD
sourcE: http://pastebin.com/djLLLCrK

edit: also, please take a look at how I'm trying to destroy the instance of a class in constructors, is this right, or it wont work at all?
Last edited on
Line 3/4/12/13/32: You've forgot to add the namespace on front, although your compiler is going to think that you've added the namespace and forgot to add the name of the functions.

1
2
3
4
5
6
7
PathSocket::PathSocket::PathSocket(args){
    //Initialising code
}

PathSocket::PathSocket::~PathSocket(args){
    //Destructive code
}


Now, I've looked into using delete this before in my own code and the C++ standards say that this is legal under conditions I can't remember where to find them XD
However I do know one obvious fact is that you can't delete automatic variables.

1
2
3
4
5
6
7
void main(){
    PathSocket a = PathSocket(5);
    //a can't be destroyed through "delete this" in constructor

    PathSocket* b = new PathSocket(5);
    //b can be destroyed through "delete this" in constructor
}


And I'm afraid I have no idea at all whether it's legal to add your current namespace into a function for it to call from that instance, I'm think that syntax may only be used for static overrides of the function
Last edited on
Topic archived. No new replies allowed.
Pages: 12