-3

I am trying to make a constructor in c++ with visual studio and I get this error :

Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

I run a diferent code from my teacher that is almost the same and it work. I'm new in oop, so don't juge please.

An example:

class Stud {
char name[30];

const () {

this->cnp[0] = 'a';
this->cnp[1] = '/0';

}
};

2 Answers2

10

Well, const normally does not stand for "constructor", but if you try really hard...

#include <string>

class ructor
{
    std::string name;

    ructor() : name("a") {}

    static const ructor make() { return ructor(); }
};      // ^^^^^^^^^^^^ lol
fredoverflow
  • 246,999
  • 92
  • 370
  • 646
5

Constructors are not written like that. Replace const() with Stud().
The "name" must be the same as the name of the class.

const means something else — I'll leave you to look it up in your textbook!

Lightness Races in Orbit
  • 369,052
  • 73
  • 620
  • 1,021