Click here to Skip to main content
15,886,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
I want to make a forward declaration for a function, which is a class member. How do I do this?

What I have tried:

I've tried this code:
C++
class TQ{
public:
	int a,b;
	int GetA(string s);
}

int TQ.GetA(string s){
	return this.a;
}


But id doesn't compile, saying that a semicolon is expected in Line 7 instead of the '.', but the semicolon doesn't solve the problem.
Posted
Updated 18-Mar-16 12:41pm
v3
Comments
Patrice T 18-Mar-16 2:28am    
And the language is ?
Nafees Hassan 18-Mar-16 2:29am    
Mentioned in the heading, D.
Patrice T 18-Mar-16 2:44am    
You just forgot to say it in TAGs.
Use Improve question to update your question.
Nafees Hassan 18-Mar-16 2:58am    
There is no tag for D.
Brisingr Aerowing 18-Mar-16 2:36am    
I noticed that in the class definition, the name of the method is Get, but the definition below is named GetA, which should cause a compiler error like the one you see.

Did you try something like:
C#
class TQ{
public:
    int a,b;
    int GetA(string s){
        return this.a;
    };
}
 
Share this answer
 
Comments
Nafees Hassan 18-Mar-16 5:21am    
I know this way works, but I want to make a forward declaration in the class (Line in C++), and define the function afterwards.
You cannot do that[^] as it isn't needed nor allowed.
 
Share this answer
 
Comments
Nafees Hassan 19-Mar-16 1:37am    
Thanks, I had nearly broken my entire code trying to do that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900