0

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..

Edited by __avd: Added [code] tags. Do wrap your programming code blocks within [code] ... [/code] tags

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Rookie09
0

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.

0

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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.