我正在尝试为共享内存对象运行程序。我的代码如下:
#include <stdio.h> /*adding standard input output library*/
#include <stdlib.h> /*standard library for four variable types, several macros, and various functions for performing general functions*/
#include <string.h> /*adding string library*/
#include <sys/fcntl.h> /* library for file control options */
#include <sys/shm.h> /*library for shared memory facility*/
#include <sys/stat.h> /*data returned by the stat() function*/
int main()
{
/* the size (in bytes) of shared memory object */
const int SIZE=4096;
/* name of the shared memory object */
const char …Run Code Online (Sandbox Code Playgroud) #include <iostream>
class Abc // created class with name Abc
{
void display()//member function
{
cout<<"Displaying NO."<<endl;
}
};
int main()
{
Abc obj;//creating object of the class
obj.display();//calling member function inside class
}
Run Code Online (Sandbox Code Playgroud)
它返回错误为
main.cpp: In function 'int main()':
main.cpp:5:10: error: 'void Abc::display()' is private
void display()
^
main.cpp:13:17: error: within this context
obj.display();
^
Run Code Online (Sandbox Code Playgroud)
我试图使显示功能,public int main但它给出了错误
main.cpp:5:11: error: expected ':' before 'void'
public void display()
^
Run Code Online (Sandbox Code Playgroud)