+ 1
Sepreat files for classes in C++
Sololearn not provide the exact program in this case I take video tutorials online but there code is not working on my PC.so I need the Full program of Sepreat files for classes.Help please
13 Antworten
+ 5
File name: myClass.h
#pragma once // not standard but is widely used instead of the preprocessor condition block
class myClass {
public:
myClass();
void doStuff();
};
~~~~~~~
File name: myClass.cpp
#include <iostream>
#include "myClass.h"
myClass::myClass() {
std::cout << "myClass object created.\n";
}
void myClass::doStuff() {
std::cout << "Doing stuff...\n";
}
~~~~~~~~
File name: main.cpp
#include "myClass.h"
int main() {
myClass mc;
mc.doStuff();
}
~~~~~~~~~
Output:
myClass object created.
Doing stuff...
+ 6
It's easy! Don't focus on the IDE. All you need to do is create 3 files as follow:
myClass.h --> Class interface
myClass.cpp --> Class implementation
main.cpp --> Client program
I'll give you a simple example in a couple of minutes.
+ 4
Here is a simple instruction if you get stuck somewhere.
http://cs.uno.edu/~jaime/Courses/2025/devCpp2025Instructions.html
+ 3
What IDE are you using, now?
+ 2
I thought this video explained it okay easy, maybe it helps you.
https://m.youtube.com/watch?v=9RJTQmK0YPI
+ 1
See this
https://www.sololearn.com/learn/CPlusPlus/1955/
I need code for this program
+ 1
I finally make this simple one
Main cpp
#include <iostream>
#include "Burrito.h"
using namespace std;
int main()
{
Burrito bo;
return 0
}
Header file
#ifndef BURRITO_H
#define BURRITO_H
class Burrito{
public:
Burrito();
};
#endif
Last cpp file
#include "Burrito.h"
#include <iostream>
using namespace std;
Burrito::Burrito()
{
Cout << "Hello world ";
}
+ 1
Last time I didn't know why this program not work But this time it work successfully.
Thanks again
C++ Soldier (Babak)
And other helpers too
0
Sorry HonFu I can't understand because the compiler is totally different it's program is also different from solo learn and new Boston method.I need a program by the method of creating Class that open two new files and so on .See the solo learn explanation and tell me
0
I am going to try it now then I tell you
0
Dev C++ 5.11
0
OK let's see it