Member Avatar for Unhnd_Exception

This should be easy.

Haven't writen a C++ app in over 10 years. Trying to delve back into it.

Will someone be kindley enough to show me a sample Function and Procdure

Name the function AnyFunction that returns and integer.

Name the procedure AnyProcdure

Heres my .h and .cpp

#pragma once

ref class clsHelloWorld
{

public:
    clsHelloWorld(void);


};
#include "StdAfx.h"
#include "clsHelloWorld.h"

clsHelloWorld::clsHelloWorld(void)
{
}

I'm assuming you selected a CLR/Winforms application in VC++. If you want to make a standard C++ program select Win32 Console Application instead. The CLR implementation of C++ (C++/CLI) relies on the .NET libraries and a slightly different syntax (as you're finding with the "ref class" keyword. There are a few good sites out there like http://www.functionx.com/vccli/index.htm but honestly if you want to do .NET programming and you're just starting again you're probably better off with C#, IMHO.

Member Avatar for Unhnd_Exception

Yeah, I selected a winforms app. Then added a class to it.

Just trying to get some C++ syntax on a function and procedure.

I program in C# and vb.net. So you won't find me asking any questions about that. Just screwing aroung with C++.

Any syntax would be good for a standard function or procedure.

To have your class interact with the form, you need to send in an instance of the form:

public ref class ClassData
	{
	private:
		System::Windows::Forms::Form ^ frm1;
	public:
		ClassData(void);
		ClassData(System::Windows::Forms::Form ^ frm1);
		void ChangeButtonText();
	};

Then declare an object of the class in the private variables section of Form1.h: ClassData ^ Cd; . Instantiate it in your Form1 constructor or wherever, passing in the form as "this". Then use it as you would any other object (so you can call Cd->ChangeButtonText();

Member Avatar for Unhnd_Exception

jonsca,

I appreciate you responding, but i don't think you understand the simplicity of this question.

All I'm looking for is a sample function and a sample sub in a .h and a .cpp.

Take this for vb example

private function AnyFunction() as integer
return 1
end function

private sub AnySub()
'do anything
end sub

Im just tying to get that into C++ syntax in the .h and .cpp file that I posted first.

I know it's not exactly what you are looking for, but see if you can adapt it (I don't want to take away all your fun!)

I think we overlapped. That wasn't in response to what you said. What do you mean by a procedure?

You need a prototype for your method (I tend to reserve function for procedural programming) in the header file like: int AnyFunction(); under the "public:" section.

and

int clsHelloWorld::AnyFunction()
{
    return 1;
}

in the .cpp file.

I think the equivalent of a procedure in C++ would be a method "returning" void.

Member Avatar for Unhnd_Exception

the response was updated while creating the orginal version

Member Avatar for Unhnd_Exception

Thank You,

Thats all this question was.

No problem. Your specification at first sounded a bit like an assignment, which was why I hesitated, I wanted you to find some of it for yourself if that had been the case. I meant no hard feelings.

Happy holidays!

Member Avatar for Unhnd_Exception

Jonsca,

I'm an all-star vb programmer. Have no intentions of programming in C++.

Just screwing aroung with C++ like I said.

Kept getting a build error. Didn't have the int in the right place.

Happy Holidays to you to!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.