Allright dudes ,listen up .. i am programming C++ about 2 days now , so i am not into it , in any way , so the problem is that the preproceccor macro #define should trigger the constructor , but the problem is that i got that annoying compiler error : "expected primary expression.." (on DEV C++ integrated compiler)

Here's the code :

#include <iostream>
#include <cstdlib>
#include <string>

using namespace std ;
using std::string ;

#define CREATE_TABLE(name)  (MyClass mc(name)) //<----- 2 damn hours same shit error msg

string create_table(string name){
	
	return name ;

}

class MyClass
{
public:
    MyClass(string name) 
    { 
        cout << "class name is :" << name;
		
    }

private:
	string name ;
};
  
int main()
{
	CREATE_TABLE(name) ;  
    std::cin.ignore( std::numeric_limits<streamsize>::max(), '\n' );
}

ty guys..

1. name must be defined in maiun(). Since the constructor of MyClass expects a std::satring then declare std::string name in main()

2. Remove the parentheses in the macro

3. There is no point in using that macro other than as an educational tool.

And, of course, it would look something like this:

#include <iostream>
#include <string>
#include <conio.h>

using namespace std;
using std::string;

#define CREATE_TABLE(name)  MyClass mc(name)

class MyClass
{
public:
    MyClass(string name) 
    { 
        cout << "class name is : " << name;
    }

private:
	string name;
};
  
int main()
{
	string name = "Example";
	CREATE_TABLE(name);
	//CREATE_TABLE("Example");

	getch();
	return 0;
}

But, as Ancient Dragon pointed out, there's no real use for such a macro.

thx a lot guys , you really helped me out here , nah , the whole thing is to "simulate" SQL in C++ , but whatever..have a nice day

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.